Class: Tdc::Generators::StandardGenerator

Inherits:
GeneratorBase show all
Includes:
DefinitionSourcable
Defined in:
lib/tdc/generators/standard_generator.rb

Overview

Knows how to provide a configurable instance definition.

Instance Attribute Summary collapse

Attributes inherited from GeneratorBase

#generation_context

Instance Method Summary collapse

Methods included from DefinitionSourcable

#configure_definition_source

Methods inherited from GeneratorBase

#initialize, #instance_definitions

Constructor Details

This class inherits a constructor from Tdc::Generators::GeneratorBase

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tdc::Generators::DefinitionSourcable

Instance Attribute Details

#instance_definitionObject (readonly)

Returns the value of attribute instance_definition.



9
10
11
# File 'lib/tdc/generators/standard_generator.rb', line 9

def instance_definition
  @instance_definition
end

Instance Method Details

#generateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tdc/generators/standard_generator.rb', line 13

def generate
  CatalogEntries.new.tap do |catalog_entries|
    instance_definitions.each do |instance_definition|
      configure_instance_definition(instance_definition)

      # Delete the tag so that the models do not need to filter it out.
      tag = instance_definition.delete("tag")

      generated = run_resolvers_and_generate_instance

      # Add generated instance to the catalog entries whenever a tag provided.
      catalog_entries.add_catalog_entry(tag, generated) if tag
    end
  end
end

#generate_instanceObject

Hook method: subclasses are expected to define how to generate a model instance.



39
40
41
# File 'lib/tdc/generators/standard_generator.rb', line 39

def generate_instance
  raise Tdc::MissingOverrideError, "Implement the 'generate_instance' method"
end

#run_definition_resolvers(_instance_definition) ⇒ Object

Hook method: subclasses may include the DefinitionResolvable concern to override.



46
47
48
# File 'lib/tdc/generators/standard_generator.rb', line 46

def run_definition_resolvers(_instance_definition)
  # Do nothing
end

#run_resolvers_and_generate_instanceObject



29
30
31
32
33
34
# File 'lib/tdc/generators/standard_generator.rb', line 29

def run_resolvers_and_generate_instance
  run_extended_attribute_interpreters(instance_definition)
  run_definition_resolvers(instance_definition)

  generate_instance
end