Sha256: 2de56c3a9304f8d493822860af3427194456773bc5514d4067ebe1dae51bae1a
Contents?: true
Size: 973 Bytes
Versions: 1
Compression:
Stored size: 973 Bytes
Contents
module NinjaModel module Marshalling extend ActiveSupport::Concern module InstanceMethods 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 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ninja-model-1.0.5 | lib/ninja_model/marshalling.rb |