Class: Usine::Factory
- Inherits:
-
Object
- Object
- Usine::Factory
- Defined in:
- lib/usine/factory.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluated_factory ⇒ Object
-
#initialize(mode, operation, attributes = {}) ⇒ Factory
constructor
A new instance of Factory.
- #merged_attributes ⇒ Object
- #process! ⇒ Object
Constructor Details
#initialize(mode, operation, attributes = {}) ⇒ Factory
Returns a new instance of Factory.
13 14 15 16 17 18 19 |
# File 'lib/usine/factory.rb', line 13 def initialize(mode, operation, attributes = {}) @mode = mode @operation = operation @definitions = attributes.delete(:definitions) || Usine.definitions.fetch(operation, []) @sequences = attributes.delete(:sequences) || Usine.sequences @attributes = attributes || {} end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/usine/factory.rb', line 5 def attributes @attributes end |
#definition ⇒ Object
Returns the value of attribute definition.
6 7 8 |
# File 'lib/usine/factory.rb', line 6 def definition @definition end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
3 4 5 |
# File 'lib/usine/factory.rb', line 3 def mode @mode end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
4 5 6 |
# File 'lib/usine/factory.rb', line 4 def operation @operation end |
Class Method Details
.call(mode, operation, attributes = {}) ⇒ Object
8 9 10 11 |
# File 'lib/usine/factory.rb', line 8 def self.call(mode, operation, attributes = {}) factory = new(mode, operation, attributes, definitions) factory.process! end |
Instance Method Details
#evaluated_factory ⇒ Object
29 30 31 |
# File 'lib/usine/factory.rb', line 29 def evaluated_factory @evaluated_factory ||= evaluate_with_definitions(@sequences) end |
#merged_attributes ⇒ Object
25 26 27 |
# File 'lib/usine/factory.rb', line 25 def merged_attributes evaluated_factory.attributes.merge(@attributes) end |
#process! ⇒ Object
21 22 23 |
# File 'lib/usine/factory.rb', line 21 def process! @operation.send(@mode, merged_attributes) end |