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
- .new(attributes) ⇒ ReadOnlyAttributeSet constructor
Instance Attribute Summary
- #attributes readonly
- #each_value readonly
- #except readonly
- #fetch readonly
- #read_only? ⇒ Boolean readonly
- #all_initialized? ⇒ Boolean readonly private
Instance Method Summary
- #==(other)
- #[](name)
- #cast_types
- #deep_dup
-
#include?(name)
Alias for #key?.
- #key?(name) ⇒ Boolean (also: #include?)
- #keys
- #map(&block)
-
#to_h
Alias for #to_hash.
- #to_hash (also: #to_h)
- #values
- #writable
- #default_attribute(name) private
Constructor Details
.new(attributes) ⇒ ReadOnlyAttributeSet
# 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 ]#include?(name)
Alias for #key?.
# File 'activemodel/lib/active_model/attribute_set.rb', line 34
alias :include? :key?
#key?(name) ⇒ Boolean
Also known as: #include?
# 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.
# File 'activemodel/lib/active_model/attribute_set.rb', line 48
alias :to_h :to_hash
#to_hash Also known as: #to_h
[ GitHub ]#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