Class: DatashiftJourney::FormObjectFactory
- Inherits:
-
Object
- Object
- DatashiftJourney::FormObjectFactory
- Defined in:
- app/factories/datashift_journey/form_object_factory.rb
Class Method Summary collapse
- .form_name(state) ⇒ Object
-
.form_object_for(journey_plan) ⇒ Object
Create a form object from the current states Form class.
- .state_name(form) ⇒ Object
Class Method Details
.form_name(state) ⇒ Object
21 22 23 24 25 |
# File 'app/factories/datashift_journey/form_object_factory.rb', line 21 def form_name(state) @form_name_mod ||= Configuration.call.forms_module_name "#{@form_name_mod}::#{state.to_s.camelize}Form" end |
.form_object_for(journey_plan) ⇒ Object
Create a form object from the current states Form class
Each form can provide a factory to drive how its constructed, or can rely on the base classes factory method
12 13 14 15 16 17 18 19 |
# File 'app/factories/datashift_journey/form_object_factory.rb', line 12 def form_object_for(journey_plan) # Get ReForm form for current state klass = form_class_for(journey_plan) raise(FormObjectError, "Failed to load form class #{form_name(journey_plan.state)} for state #{journey_plan.state}") unless klass # Create new instance of form for current journey instance klass.new(journey_plan) end |
.state_name(form) ⇒ Object
27 28 29 30 |
# File 'app/factories/datashift_journey/form_object_factory.rb', line 27 def state_name(form) return form.chomp('Form').underscore if form.is_a?(String) form.class.name.chomp('Form').underscore end |