Class: Foobara::Generators::Generate

Inherits:
Command
  • Object
show all
Defined in:
foobara-files-generator-0.0.5/src/generate.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes included from CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from CommandPatternImplementation::Concerns::Runtime

#exception, #outcome

Attributes included from CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Instance Method Summary collapse

Methods inherited from Command

install!, reset_all

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::Reflection

#initialize

Methods included from CommandPatternImplementation::Concerns::DomainMappers

#domain_map, #domain_map!, #run_mapped_subcommand!

Methods included from CommandPatternImplementation::Concerns::Subcommands

#run_subcommand!, #subcommand?

Methods included from CommandPatternImplementation::Concerns::Entities

#load_entities, #load_records

Methods included from CommandPatternImplementation::Concerns::Transactions

#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions

Methods included from CommandPatternImplementation::Concerns::StateMachine

#state_machine

Methods included from CommandPatternImplementation::Concerns::Runtime

#execute, #halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records

Methods included from CommandPatternImplementation::Concerns::Errors

#initialize

Methods included from CommandPatternImplementation::Concerns::Inputs

#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?

Methods included from TruncatedInspect

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Instance Attribute Details

#element_to_generateObject

Returns the value of attribute element_to_generate.



9
10
11
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 9

def element_to_generate
  @element_to_generate
end

Instance Method Details

#base_generatorObject



11
12
13
14
15
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 11

def base_generator
  # :nocov:
  raise "subclass responsibility"
  # :nocov:
end

#each_element_to_generateObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 29

def each_element_to_generate
  until elements_to_generate.empty?
    element_to_generate = elements_to_generate.first
    elements_to_generate.delete(element_to_generate)

    generators = if element_to_generate.is_a?(FilesGenerator)
                   if generated.include?(element_to_generate)
                     []
                   else
                     elements_to_generate << element_to_generate.relevant_manifest
                     [element_to_generate]
                   end
                 else
                   if generated_elements.include?(element_to_generate)
                     next
                   end

                   generated_elements << element_to_generate

                   base_generator.generators_for(element_to_generate).select do |generator|
                     generator.applicable? && !generated.include?(generator)
                   end
                 end

    generators.each do |generator|
      # TODO: change this name
      self.element_to_generate = generator
      generated << generator
      yield
    end
  end
end

#elements_to_generateObject



17
18
19
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 17

def elements_to_generate
  @elements_to_generate ||= Set.new
end

#generate_elementObject



62
63
64
65
66
67
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 62

def generate_element
  return unless element_to_generate.applicable?

  paths_to_source_code[Util.array(element_to_generate.target_path).join("/")] =
    element_to_generate.generate(elements_to_generate)
end

#generatedObject



21
22
23
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 21

def generated
  @generated ||= Set.new
end

#generated_elementsObject



25
26
27
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 25

def generated_elements
  @generated_elements ||= Set.new
end

#include_non_templated_filesObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 69

def include_non_templated_files
  templates_dir_pathname = Pathname.new(templates_dir)

  Find.find(templates_dir) do |file_path|
    next if File.directory?(file_path)
    next if file_path.end_with?(".erb")

    file_path = Pathname.new(file_path)

    relative_path = file_path.relative_path_from(templates_dir_pathname)

    paths_to_source_code[relative_path.to_s] = File.read(file_path)
  end
end

#paths_to_source_codeObject



88
89
90
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 88

def paths_to_source_code
  @paths_to_source_code ||= {}
end

#templates_dirObject



84
85
86
# File 'foobara-files-generator-0.0.5/src/generate.rb', line 84

def templates_dir
  base_generator.templates_dir
end