Sha256: 5c3bb68c79ac91648638225c7db324cb9c7fadb489d14083bccf28b26187950c

Contents?: true

Size: 784 Bytes

Versions: 13

Compression:

Stored size: 784 Bytes

Contents

module Spira
  module Serialization
    ##
    # 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
    def encode_with(coder)
      coder["subject"] = subject
      attributes.each {|p,v| coder[p.to_s] = v if v}
    end

    ##
    # 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
    def init_with(coder)
      instance_variable_set(:"@subject", coder["subject"])
      assign_attributes coder.map.except("subject")
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spira-3.3.0 lib/spira/serialization.rb
spira-3.2.0 lib/spira/serialization.rb
spira-3.1.1 lib/spira/serialization.rb
spira-3.1.0 lib/spira/serialization.rb
spira-3.0.0 lib/spira/serialization.rb
spira-2.1.0 lib/spira/serialization.rb
spira-2.0.2 lib/spira/serialization.rb
spira-2.0.1 lib/spira/serialization.rb
spira-2.0.0 lib/spira/serialization.rb
spira-1.1.1 lib/spira/serialization.rb
spira-0.7.1 lib/spira/serialization.rb
spira-0.7 lib/spira/serialization.rb
spira-0.5.0 lib/spira/serialization.rb