Class: RailsWorkflow::Context
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RailsWorkflow::Context
- Defined in:
- app/models/rails_workflow/context.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #init_data ⇒ Object
- #prepare_body(body) ⇒ Object
- #prepare_data(data) ⇒ Object
- #serialize_data ⇒ Object
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'app/models/rails_workflow/context.rb', line 4 def data @data end |
Instance Method Details
#init_data ⇒ Object
15 16 17 |
# File 'app/models/rails_workflow/context.rb', line 15 def init_data self.data = prepare_body(body).with_indifferent_access end |
#prepare_body(body) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/rails_workflow/context.rb', line 19 def prepare_body body if body.is_a? Array body.map do |element| prepare_body element end elsif body.is_a? Hash if body.keys == ["id", "class"] body["class"].constantize.find(body["id"]) else res = {} body.each_pair do |key, value| res[key] = prepare_body(value) end res end else body end end |
#prepare_data(data) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/rails_workflow/context.rb', line 42 def prepare_data data if data.is_a? ActiveRecord::Base { id: data.id, class: data.class.to_s } elsif data.is_a? Array data.map do |element| prepare_data element end elsif data.is_a? Hash res = {} data.each_pair do |key, value| res[key] = prepare_data(value) end res else data end end |
#serialize_data ⇒ Object
11 12 13 |
# File 'app/models/rails_workflow/context.rb', line 11 def serialize_data self.body = prepare_data(self.data) end |