Class: LexoRanker::Rankable

Inherits:
Module
  • Object
show all
Defined in:
lib/lexoranker/rankable.rb

Overview

Module for adding convenience methods to ActiveRecord or Sequel database adapters to support ranking items. See LexoRanker::RankableMethods::Base for class and instance methods added from this module.

Instance Method Summary collapse

Constructor Details

#initialize(adapter = :active_record) ⇒ Object

Instance the module to be included in the class for the database adapter.

Examples:

Include LexoRanker::Rankable in an ActiveRecord model

class MyList < ActiveRecord::Base
  include LexoRanker::Rankable.new(:active_record)
end

Parameters:

  • adapter (Symbol) (defaults to: :active_record)

    the adapter to use



41
42
43
44
45
46
47
48
49
50
# File 'lib/lexoranker/rankable.rb', line 41

def initialize(adapter = :active_record)
  @adapter_setting = adapter
  @adapter = select_adapter
  class_eval do
    def self.included(klass)
      klass.include(LexoRanker::RankableMethods::Base)
      klass.include(@adapter)
    end
  end
end