Class: ActiveType::Util::UnmutableAttributes
- Inherits:
-
Object
- Object
- ActiveType::Util::UnmutableAttributes
show all
- Defined in:
- lib/active_type/util/unmutable_attributes.rb
Overview
This object is used as a substitute for a record’s @attributes. Reading from the original @attributes is still allowed, to enable ‘#inspect` and similar functions. But the @attributes can no longer be mutated and will raise instead.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of UnmutableAttributes.
15
16
17
|
# File 'lib/active_type/util/unmutable_attributes.rb', line 15
def initialize(attributes)
@original_attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
35
36
37
|
# File 'lib/active_type/util/unmutable_attributes.rb', line 35
def method_missing(*args)
raise MutationAfterCastError, 'Changing a record that has been used to create an ActiveType::Record could have unexpected side effects!'
end
|
Instance Attribute Details
#original_attributes ⇒ Object
Returns the value of attribute original_attributes.
12
13
14
|
# File 'lib/active_type/util/unmutable_attributes.rb', line 12
def original_attributes
@original_attributes
end
|
Instance Method Details
23
24
25
|
# File 'lib/active_type/util/unmutable_attributes.rb', line 23
def [](key)
original_attributes[key]
end
|
#fetch_value(key) ⇒ Object
19
20
21
|
# File 'lib/active_type/util/unmutable_attributes.rb', line 19
def fetch_value(key)
original_attributes.fetch_value(key)
end
|
#key?(key) ⇒ Boolean
27
28
29
|
# File 'lib/active_type/util/unmutable_attributes.rb', line 27
def key?(key)
original_attributes.key?(key)
end
|
31
32
33
|
# File 'lib/active_type/util/unmutable_attributes.rb', line 31
def keys
original_attributes.keys
end
|