Module: ActsAsReplaceable::InstanceMethods

Defined in:
lib/acts_as_replaceable/acts_as_replaceable.rb

Instance Method Summary collapse

Instance Method Details

#create_record(*args) ⇒ Object

Override the create or update method so we can run callbacks, but opt not to save if we don’t need to



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/acts_as_replaceable/acts_as_replaceable.rb', line 34

def create_record(*args)
  find_and_replace
  if @has_not_changed
    logger.info "(acts_as_replaceable) Found unchanged #{self.class.to_s} ##{id} #{"- Name: #{name}" if respond_to?('name')}"
  elsif @has_been_replaced
    update_record(*args)
    logger.info "(acts_as_replaceable) Updated existing #{self.class.to_s} ##{id} #{"- Name: #{name}" if respond_to?('name')}"
  else
    super
    logger.info "(acts_as_replaceable) Created #{self.class.to_s} ##{id} #{"- Name: #{name}" if respond_to?('name')}"
  end

  return true
end

#find_and_replaceObject



49
50
51
# File 'lib/acts_as_replaceable/acts_as_replaceable.rb', line 49

def find_and_replace
  replace(find_duplicate)
end