Sha256: 5a532be9b75afa557cbb2d15fcb53e52971e2782d2867414cc290f77b40d6fe0

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

require 'active_support'

require 'recommendable/version'
require 'recommendable/configuration'
require 'recommendable/helpers'

require 'recommendable/rater'
require 'recommendable/ratable'

require 'recommendable/workers/sidekiq'
require 'recommendable/workers/resque'
require 'recommendable/workers/delayed_job'
require 'recommendable/workers/torque_box'

module Recommendable
  class << self
    def redis() config.redis end

    def query(klass, ids)
        Recommendable::Helpers::Queriers.send(Recommendable.config.orm, klass, ids)
      rescue NoMethodError
        warn 'Your ORM is not currently supported. Please open an issue at https://github.com/davidcelis/recommendable'
    end

    def enqueue(user_id)
      user_id = user_id.id if user_id.is_a?(Recommendable.config.user_class)

      if defined?(::Sidekiq)
        Recommendable::Workers::Sidekiq.perform_async(user_id)
      elsif defined?(::Resque)
        Resque.enqueue(Recommendable::Workers::Resque, user_id)
      elsif defined?(::Delayed::Job)
        Delayed::Job.enqueue(Recommendable::Workers::DelayedJob.new(user_id))
      elsif defined?(::TorqueBox::Messaging::Backgroundable)
        Recommendable::Workers::TorqueBox.enqueue(user_id)
      elsif defined?(::Rails::Queueing)
        unless Rails.queue.any? { |w| w.user_id == user_id }
          Rails.queue.push(Recommendable::Workers::Rails.new(user_id))
          Rails.application.queue_consumer.start
        end
      end
    end
  end
end

require 'recommendable/orm/active_record' if defined?(ActiveRecord::Base)
require 'recommendable/orm/data_mapper' if defined?(DataMapper::Resource)
require 'recommendable/orm/mongoid' if defined?(Mongoid::Document)
require 'recommendable/orm/mongo_mapper' if defined?(MongoMapper::Document)
require 'recommendable/orm/sequel' if defined?(Sequel::Model)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
recommendable-2.1.4 lib/recommendable.rb
recommendable-2.1.3 lib/recommendable.rb
recommendable-2.1.2 lib/recommendable.rb
recommendable-2.1.1 lib/recommendable.rb
recommendable-2.1.0.2 lib/recommendable.rb
recommendable-2.1.0.1 lib/recommendable.rb