Class: Journea::Journey
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Journea::Journey
- Includes:
- Statesman::Adapters::ActiveRecordQueries
- Defined in:
- app/models/journea/journey.rb
Instance Method Summary collapse
- #data ⇒ Object
- #data_for_form(step_object) ⇒ Object
-
#save_data(step_object) ⇒ Object
Instance methods.
-
#state_machine ⇒ Object
State Machine related.
Instance Method Details
#data ⇒ Object
49 50 51 |
# File 'app/models/journea/journey.rb', line 49 def data Data.new(Keyvalue.where(journey: self)) end |
#data_for_form(step_object) ⇒ Object
42 43 44 45 46 47 |
# File 'app/models/journea/journey.rb', line 42 def data_for_form(step_object) data = Keyvalue.where(key: step_object.attributes.keys, journey: self).map do |kv| [kv.key.to_sym, kv.value] end data.to_h end |
#save_data(step_object) ⇒ Object
Instance methods
31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/journea/journey.rb', line 31 def save_data(step_object) return false unless step_object.valid? step_object.attributes.each do |k, v| key_value_pair = Keyvalue.find_or_initialize_by(key: k.to_s, journey: self) key_value_pair.value = v key_value_pair.save end true end |
#state_machine ⇒ Object
State Machine related
11 12 13 |
# File 'app/models/journea/journey.rb', line 11 def state_machine @state_machine ||= StateMachine.new(self, transition_class: JourneyTransition) end |