Sha256: 0e2dc8d522ba5fe71ba816947b0f216882938a2319e545764e50bd870f5c5abc

Contents?: true

Size: 946 Bytes

Versions: 14

Compression:

Stored size: 946 Bytes

Contents

require 'mongoid/criteria'
require 'mongoid/document'
module RocketJob
  module Mongoid5Clients
    module Options
      extend ActiveSupport::Concern

      def with_collection(collection_name)
        self.collection_name = collection_name
        self
      end

      def collection
        return (@klass || self.class).with(persistence_options || {}).collection unless @collection_name
        (@klass || self.class).mongo_client[@collection_name]
      end

      def collection_name
        @collection_name || super
      end

      def collection_name=(collection_name)
        @collection_name = collection_name&.to_sym
      end

      private

      module ClassMethods
        def with_collection(collection_name)
          all.with_collection(collection_name)
        end
      end
    end
  end
end

::Mongoid::Criteria.include(RocketJob::Mongoid5Clients::Options)
::Mongoid::Document.include(RocketJob::Mongoid5Clients::Options)

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rocketjob-5.1.1 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-5.1.0 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-5.0.0 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-5.0.0.rc1 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-5.0.0.beta4 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-5.0.0.beta3 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-5.0.0.beta2 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-5.0.0.beta lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-4.3.0.beta2 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-4.3.0.beta lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-4.2.0 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-4.1.1 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-4.1.0 lib/rocket_job/extensions/mongoid_5/clients/options.rb
rocketjob-4.0.0 lib/rocket_job/extensions/mongoid_5/clients/options.rb