Class: ValidatesDuplicityOf::Record

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/validates_duplicity_of/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#scopeObject (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_valueObject



25
26
27
# File 'lib/validates_duplicity_of/record.rb', line 25

def attr_changed_value
  changed_attributes[attr_name]
end

#attr_valueObject

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

Returns:

  • (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