Module: LazyLazer::InstanceMethods
- Extended by:
- Forwardable
- Defined in:
- lib/lazy_lazer.rb
Overview
The methods to extend the instance with.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality check, performed using required keys.
-
#[](key_name) ⇒ Object
Return the value of the attribute, returning nil if not found.
-
#assign_attributes(new_attributes) ⇒ self
(also: #attributes=)
Update multiple attributes at once.
-
#initialize(attributes = {}) ⇒ void
Create a new instance of the class from a set of source attributes.
-
#reload ⇒ self
Reload the object.
Instance Method Details
#==(other) ⇒ Boolean
Equality check, performed using required keys.
85 86 87 88 89 90 91 92 |
# File 'lib/lazy_lazer.rb', line 85 def ==(other) return false if self.class != other.class return super if @_lazer_model.required_properties.empty? @_lazer_model.required_properties.each do |key_name| return false if read_attribute(key_name) != other.read_attribute(key_name) end true end |
#[](key_name) ⇒ Object
Return the value of the attribute, returning nil if not found.
97 98 99 100 101 |
# File 'lib/lazy_lazer.rb', line 97 def [](key_name) read_attribute(key_name) rescue MissingAttribute nil end |
#assign_attributes(new_attributes) ⇒ self Also known as: attributes=
Update multiple attributes at once.
106 107 108 109 |
# File 'lib/lazy_lazer.rb', line 106 def assign_attributes(new_attributes) new_attributes.each { |key, value| write_attribute(key, value) } self end |
#initialize(attributes = {}) ⇒ void
Create a new instance of the class from a set of source attributes.
76 77 78 79 80 |
# File 'lib/lazy_lazer.rb', line 76 def initialize(attributes = {}) @_lazer_model = InternalModel.new(self.class.instance_variable_get(:@_lazer_metadata), self) @_lazer_model.merge!(attributes) @_lazer_model.verify_required! end |
#reload ⇒ self
Reload the object. Calls #lazer_reload, then merges the results into the internal store. Also clears out the internal cache.
115 116 117 118 119 |
# File 'lib/lazy_lazer.rb', line 115 def reload new_attributes = lazer_reload.to_h @_lazer_model.merge!(new_attributes) self end |