class ValidatesDuplicityOf::Record
Attributes
attr_name[R]
scope[R]
Public Class Methods
new(record, attr_name, scope)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
attr_changed_value()
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 25 def attr_changed_value changed_attributes[attr_name] end
attr_value()
click to toggle source
Callback
attribute getter
# File lib/validates_duplicity_of/record.rb, line 12 def attr_value __getobj__[attr_name] end
attr_value=(value)
click to toggle source
Callback
attribute setter
# File lib/validates_duplicity_of/record.rb, line 17 def attr_value=(value) __getobj__[attr_name] = value end
update_required?()
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 21 def update_required? value_changed? && value_present? && record_exists? end
where_match(pattern)
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 29 def where_match(pattern) scoped_relation.where klass.arel_table[attr_name].matches(pattern) end
Private Instance Methods
klass()
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 51 def klass __getobj__.class end
record_exists?()
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 43 def record_exists? scoped_relation.where(attr_name => attr_value).exists? end
scoped_relation()
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 47 def scoped_relation scope ? klass.where(scope => __getobj__[scope]) : klass end
value_changed?()
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 35 def value_changed? changed.include? attr_name end
value_present?()
click to toggle source
# File lib/validates_duplicity_of/record.rb, line 39 def value_present? attr_value.present? end