Module: FlowMachine::FactoryMethods
- Included in:
- Workflow
- Defined in:
- lib/flow_machine/workflow/factory_methods.rb
Instance Method Summary collapse
- #class_for(object_or_class) ⇒ Object
- #for(object, options = {}) ⇒ Object
- #for_collection(collection, options = {}) ⇒ Object
Instance Method Details
#class_for(object_or_class) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/flow_machine/workflow/factory_methods.rb', line 19 def class_for(object_or_class) if object_or_class.is_a? Class "#{object_or_class.name}Workflow".constantize else class_for(object_or_class.class) end rescue NameError # if the workflow class doesn't exist nil end |
#for(object, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/flow_machine/workflow/factory_methods.rb', line 4 def for(object, = {}) # If the object is enumerable, delegate. This allows workflow_for # as shorthand return for_collection(object, ) if object.respond_to?(:map) klazz = class_for(object) return nil unless klazz klazz.new(object, ) end |
#for_collection(collection, options = {}) ⇒ Object
15 16 17 |
# File 'lib/flow_machine/workflow/factory_methods.rb', line 15 def for_collection(collection, = {}) collection.map { |item| self.for(item, ) } end |