Class: ValidatesDuplicityOf::Duplicator

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

Instance Method Summary collapse

Constructor Details

#initialize(callback, record) ⇒ Duplicator

Returns a new instance of Duplicator.



3
4
5
6
# File 'lib/validates_duplicity_of/duplicator.rb', line 3

def initialize(callback, record)
  @callback = callback
  @record = Record.new record, callback.attr_name, callback.scope
end

Instance Method Details

#validateObject

Updates the attribute of the record



9
10
11
12
13
14
15
16
17
# File 'lib/validates_duplicity_of/duplicator.rb', line 9

def validate
  return unless @record.update_required?

  if changed_attribute_match?
    @record.attr_value = @record.attr_changed_value
  else
    @record.attr_value.concat(next_index)
  end
end