Module: Quickening::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/quickening/model.rb

Overview

Quickening::Model

Module to include within your ActiveRecord::Base class definitions, either manually or via the quickening class method.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_duplicate_conditionsObject

Returns a hash meant to be used as a parameter to the query method where(..). To clarify the return value, if your model was set up like this:

class User < ActiveRecord::Base
  quickening :last_name, :ssn
  ..
end

Then when you call a method utilizing this helper, such as User#duplicates:

@user.last_name   # => 'Wayne'
@user.ssn         # => '987-65-321'
@user.duplicates  # => []

…the where(..) condition will receive the output of this method and end up with the following:

where({ last_name: 'Wayne', ssn: '987-65-321' })

Since the return of this method is simply injected into the where method, you could override this method and, theoretically, do something as follows:

def _duplicate_conditions
  ["first_name = ?, middle_name = ?, last_name = ?", *full_name.split]
end

However, as this breaks the unified definition of which columns are expected to match, be sure you won’t be breaking other aspects of the integration of this library.

Alternate override

If you want to maintain the library’s method behavior but extend it a bit, you might just want to follow the module extension scheme instead:

class User < ActiveRecord::Base
  quickening [..]

  # Custom overrides:
  module DuncanMacLeod
    def _duplicate_conditions
      @temporary_conditions || super
    end
  end
  include DuncanMacLeod
  ..
end


174
175
176
# File 'lib/quickening/model.rb', line 174

def _duplicate_conditions
  Hash[duplicate_matchers.map { |col| [col, send(col)] }]
end

#duplicatesObject

Returns a collection of records belonging to the same class/table which matches on the designated columns.

<%= render partial: 'user/duplicate', collection: @user.duplicates %>


121
122
123
# File 'lib/quickening/model.rb', line 121

def duplicates
  self.class.find_duplicates_for(self)
end