class ActiveModel::LazyAttributeHash

:nodoc:

def ==(other)

def ==(other)
  if other.is_a?(LazyAttributeHash)
    materialize == other.materialize
  else
    materialize == other
  end
end

def [](key)

def [](key)
  delegate_hash[key] || assign_default_value(key)
end

def []=(key, value)

def []=(key, value)
  delegate_hash[key] = value
end

def assign_default_value(name)

def assign_default_value(name)
  type = additional_types.fetch(name, types[name])
  value_present = true
  value = values.fetch(name) { value_present = false }
  if value_present
    delegate_hash[name] = Attribute.from_database(name, value, type)
  elsif types.key?(name)
    attr = default_attributes[name]
    if attr
      delegate_hash[name] = attr.dup
    else
      delegate_hash[name] = Attribute.uninitialized(name, type)
    end
  end
end

def deep_dup

def deep_dup
  dup.tap do |copy|
    copy.instance_variable_set(:@delegate_hash, delegate_hash.transform_values(&:dup))
  end
end

def each_key(&block)

def each_key(&block)
  keys = types.keys | values.keys | delegate_hash.keys
  keys.each(&block)
end

def initialize(types, values, additional_types, default_attributes, delegate_hash = {})

def initialize(types, values, additional_types, default_attributes, delegate_hash = {})
  @types = types
  @values = values
  @additional_types = additional_types
  @materialized = false
  @delegate_hash = delegate_hash
  @default_attributes = default_attributes
end

def initialize_dup(_)

def initialize_dup(_)
  @delegate_hash = Hash[delegate_hash]
  super
end

def key?(key)

def key?(key)
  delegate_hash.key?(key) || values.key?(key) || types.key?(key)
end

def marshal_dump

def marshal_dump
  [@types, @values, @additional_types, @default_attributes, @delegate_hash]
end

def marshal_load(values)

def marshal_load(values)
  initialize(*values)
end

def materialize

def materialize
  unless @materialized
    values.each_key { |key| self[key] }
    types.each_key { |key| self[key] }
    unless frozen?
      @materialized = true
    end
  end
  delegate_hash
end