Module: Tire::Model::Import::Strategy

Defined in:
lib/tire/model/import.rb

Overview

Importing strategies for common persistence frameworks (ActiveModel, Mongoid), as well as pagination libraries (WillPaginate, Kaminari), or a custom strategy.

Defined Under Namespace

Modules: Base Classes: ActiveRecord, Default, Kaminari, Mongoid, WillPaginate

Class Method Summary collapse

Class Method Details

.from_class(klass, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tire/model/import.rb', line 30

def self.from_class(klass, options={})
  return const_get(options[:strategy]).new(klass, options) if options[:strategy]

  case
  when defined?(::ActiveRecord) && klass.ancestors.include?(::ActiveRecord::Base)
    ActiveRecord.new klass, options
  when defined?(::Mongoid::Document) && klass.ancestors.include?(::Mongoid::Document)
    Mongoid.new klass, options
  when defined?(Kaminari) && klass.respond_to?(:page)
    Kaminari.new klass, options
  when defined?(WillPaginate) && klass.respond_to?(:paginate)
    WillPaginate.new klass, options
  else
    Default.new klass, options
  end
end