Module: NinjaModel::Marshalling::InstanceMethods
- Defined in:
- lib/ninja_model/marshalling.rb
Instance Method Summary collapse
Instance Method Details
#marshal_dump ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ninja_model/marshalling.rb', line 6 def marshal_dump exceptions = %w(@association_cache @aggregation_cache @attributes) h = self.instance_variables.inject({}) { |r, k| unless exceptions.include?(k.to_s) r[k.to_s] = instance_variable_get(k) end r } h['@attributes'] = @attributes.inject({}) { |a, (k, v)| a[k] = read_attribute(k) a } ActiveSupport::JSON.encode(h) end |
#marshal_load(data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ninja_model/marshalling.rb', line 21 def marshal_load(data) h = ActiveSupport::JSON.decode(data) h.each do |k, v| if k.eql?('@attributes') @attributes = {} v.each do |n, x| write_attribute(n, x) end else instance_variable_set(k, v) end end @association_cache = {} @aggregation_cache = {} end |