123456789_123456789_123456789_123456789_123456789_

Module: ActiveModel::AttributeSet::YAMLEncoder

Do not use. This module is for internal use only.
Relationships & Source Files
Defined in: activemodel/lib/active_model/attribute_set/yaml_encoder.rb

Overview

Attempts to do more intelligent YAML dumping of an ::ActiveModel::AttributeSet to reduce the size of the resulting string

Instance Method Summary

Instance Method Details

#decode(coder, default_types)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_set/yaml_encoder.rb', line 20

def decode(coder, default_types)
  if coder["attributes"]
    coder["attributes"]
  else
    attributes_hash = Hash[coder["concise_attributes"].map do |attr|
      if attr.type.nil?
        attr = attr.with_type(default_types[attr.name])
      end
      [attr.name, attr]
    end]
    AttributeSet.new(attributes_hash)
  end
end

#encode(attribute_set, coder, default_types)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_set/yaml_encoder.rb', line 10

def encode(attribute_set, coder, default_types)
  coder["concise_attributes"] = attribute_set.each_value.map do |attr|
    if attr.type.equal?(default_types[attr.name])
      attr.with_type(nil)
    else
      attr
    end
  end
end