123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::AttributeSet::YAMLEncoder

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(default_types) ⇒ YAMLEncoder

[ GitHub ]

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

def initialize(default_types)
  @default_types = default_types
end

Instance Attribute Details

#default_types (readonly, private)

[ GitHub ]

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

attr_reader :default_types

Instance Method Details

#decode(coder)

[ GitHub ]

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

def decode(coder)
  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)

[ GitHub ]

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

def encode(attribute_set, coder)
  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