Class: Sinclair::EqualsChecker::Reader Private
- Defined in:
- lib/sinclair/equals_checker/reader.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class capable of reading an attribute from models
Class Method Summary collapse
-
.attributes_match?(attribute, model, other) ⇒ TrueClass, FalseClass
private
Checks if two attributes from 2 object match.
Instance Method Summary collapse
-
#initialize(attribute) ⇒ Reader
constructor
private
A new instance of Reader.
-
#read_from(model) ⇒ Object
private
Reads the
attribute
from the model.
Constructor Details
#initialize(attribute) ⇒ Reader
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Reader.
29 30 31 |
# File 'lib/sinclair/equals_checker/reader.rb', line 29 def initialize(attribute) @attribute = attribute end |
Class Method Details
.attributes_match?(attribute, model, other) ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if two attributes from 2 object match
21 22 23 24 25 |
# File 'lib/sinclair/equals_checker/reader.rb', line 21 def self.attributes_match?(attribute, model, other) reader = new(attribute) reader.read_from(model) == reader.read_from(other) end |
Instance Method Details
#read_from(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads the attribute
from the model
When attribute is a method name, calls that method on the model
When attribute is an instance variable name, that is read directly from the model
42 43 44 45 46 |
# File 'lib/sinclair/equals_checker/reader.rb', line 42 def read_from(model) return model.send(attribute) unless attribute.to_s.match?(/^@.*/) model.instance_variable_get(attribute) end |