Module: Tdc::Generators::DefinitionSourcable
- Extended by:
- ActiveSupport::Concern
- Included in:
- StandardGenerator
- Defined in:
- lib/tdc/generators/definition_sourcable.rb
Overview
Creates ghost methods for use in generators.
All ghost methods are named ‘key’_definition or ‘key’_definition_optional where ‘key’ is a key into the instance_definition hash.
Choose optional if the key may not be present in the instance_definition.
Example:
If an instance definition had “line” and “replenishment_parameters” keys then the following ghost methods could be used to refer to the value associated with those keys:
line_definition
line_definition_optional
replenishment_parameters_definition
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
39 40 41 42 43 44 45 46 47 |
# File 'lib/tdc/generators/definition_sourcable.rb', line 39 def method_missing(method, *args) if ghost_definition?(method) definition_source.fetch(method.to_s.gsub(/_definition$/, "")) elsif ghost_optional_definition?(method) definition_source[method.to_s.gsub(/_definition_optional$/, "")] else super end end |
Instance Method Details
#configure_definition_source(definition) ⇒ Object
33 34 35 |
# File 'lib/tdc/generators/definition_sourcable.rb', line 33 def configure_definition_source(definition) @definition_source = definition end |