Class: ValidatesDuplicityOf::Record
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ValidatesDuplicityOf::Record
- Defined in:
- lib/validates_duplicity_of/record.rb
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #attr_changed_value ⇒ Object
-
#attr_value ⇒ Object
Callback attribute getter.
-
#attr_value=(value) ⇒ Object
Callback attribute setter.
-
#initialize(record, attr_name, scope) ⇒ Record
constructor
A new instance of Record.
- #update_required? ⇒ Boolean
- #where_match(pattern) ⇒ Object
Constructor Details
#initialize(record, attr_name, scope) ⇒ Record
Returns a new instance of Record.
5 6 7 8 9 |
# File 'lib/validates_duplicity_of/record.rb', line 5 def initialize(record, attr_name, scope) super(record) @attr_name = attr_name.to_s @scope = scope end |
Instance Attribute Details
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
3 4 5 |
# File 'lib/validates_duplicity_of/record.rb', line 3 def attr_name @attr_name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
3 4 5 |
# File 'lib/validates_duplicity_of/record.rb', line 3 def scope @scope end |
Instance Method Details
#attr_changed_value ⇒ Object
25 26 27 |
# File 'lib/validates_duplicity_of/record.rb', line 25 def attr_changed_value changed_attributes[attr_name] end |
#attr_value ⇒ Object
Callback attribute getter
12 13 14 |
# File 'lib/validates_duplicity_of/record.rb', line 12 def attr_value __getobj__[attr_name] end |
#attr_value=(value) ⇒ Object
Callback attribute setter
17 18 19 |
# File 'lib/validates_duplicity_of/record.rb', line 17 def attr_value=(value) __getobj__[attr_name] = value end |
#update_required? ⇒ Boolean
21 22 23 |
# File 'lib/validates_duplicity_of/record.rb', line 21 def update_required? value_changed? && value_present? && record_exists? end |
#where_match(pattern) ⇒ Object
29 30 31 |
# File 'lib/validates_duplicity_of/record.rb', line 29 def where_match(pattern) scoped_relation.where klass.arel_table[attr_name].matches(pattern) end |