123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::ReadOnlyAttributeSet

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(attributes) ⇒ ReadOnlyAttributeSet

Raises:

  • (ArgumentError)
[ GitHub ]

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

def initialize(attributes)
  @attributes = attributes
  raise ArgumentError, "all attributes should be initialized" unless all_initialized?
  freeze
end

Instance Attribute Details

#all_initialized? ⇒ Boolean (readonly, private)

[ GitHub ]

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

def all_initialized?
  attributes.values.all? { |v| v.initialized? }
end

#attributes (readonly)

[ GitHub ]

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

attr_reader :attributes

#each_value (readonly)

[ GitHub ]

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

delegate :each_value, :fetch, :except, to: :attributes

#except (readonly)

[ GitHub ]

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

delegate :each_value, :fetch, :except, to: :attributes

#fetch (readonly)

[ GitHub ]

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

delegate :each_value, :fetch, :except, to: :attributes

#read_only? ⇒ Boolean (readonly)

[ GitHub ]

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

def read_only?
  true
end

Instance Method Details

#==(other)

[ GitHub ]

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

def ==(other)
  other.class == self.class && attributes == other.attributes
end

#[](name)

[ GitHub ]

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

def [](name)
  @attributes[name] || default_attribute(name)
end

#cast_types

[ GitHub ]

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

def cast_types
  attributes.transform_values(&:type)
end

#deep_dup

[ GitHub ]

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

def deep_dup
  self.class.new(attributes.transform_values(&:deep_dup))
end

#default_attribute(name) (private)

[ GitHub ]

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

def default_attribute(name)
  Attribute.null(name)
end

#include?(name)

Alias for #key?.

[ GitHub ]

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

alias :include? :key?

#key?(name) ⇒ Boolean Also known as: #include?

[ GitHub ]

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

def key?(name)
  attributes.key?(name)
end

#keys

[ GitHub ]

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

def keys
  attributes.keys
end

#map(&block)

[ GitHub ]

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

def map(&block)
  new_attributes = attributes.transform_values(&block)
  self.class.new(new_attributes)
end

#to_h

Alias for #to_hash.

[ GitHub ]

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

alias :to_h :to_hash

#to_hash Also known as: #to_h

[ GitHub ]

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

def to_hash
  keys.index_with { |name| self[name].value }
end

#values

[ GitHub ]

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

def values
  attributes.values
end

#writable

[ GitHub ]

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

def writable
  AttributeSet.new(attributes.transform_values(&:dup))
end