module Spira::Serialization
Public Instance Methods
encode_with(coder)
click to toggle source
Support for Psych (YAML) custom serializer.
This causes the subject and all attributes to be saved to a YAML or JSON serialization in such a way that they can be restored in the future.
@param [Psych::Coder] coder
# File lib/spira/serialization.rb, line 10 def encode_with(coder) coder["subject"] = subject attributes.each {|p,v| coder[p.to_s] = v if v} end
init_with(coder)
click to toggle source
Support for Psych (YAML) custom de-serializer.
Updates a previously allocated Spira::Base
instance to that of a previously serialized instance.
@param [Psych::Coder] coder
# File lib/spira/serialization.rb, line 22 def init_with(coder) instance_variable_set(:"@subject", coder["subject"]) assign_attributes coder.map.except("subject") end