Sha256: f6f0b8bfc0f6667d35182100207e5b51f96245e943a02382fb7310ca96235065

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8
module Mongoid
  module Contextual
    module Command

      # @attribute [r] collection The collection to query against.
      # @attribute [r] criteria The criteria for the context.
      attr_reader :collection, :criteria

      # The database command that is being built to send to the db.
      #
      # @example Get the command.
      #   command.command
      #
      # @return [ Hash ] The db command.
      #
      # @since 3.0.0
      def command
        @command ||= {}
      end

      # Get the database session.
      #
      # @example Get the session.
      #   command.session
      #
      # @return [ Session ] The Moped session.
      #
      # @since 3.0.0
      def session
        collection.database.session
      end

      private

      # Execute the block setting field limitations.
      #
      # @api private
      #
      # @example Execute with field limitations.
      #   text_search.selecting do
      #     #...
      #   end
      #
      # @param [ Symbol ] param The name of the command parameter.
      #
      # @return [ Object ] The result of the yield.
      #
      # @since 4.0.0
      def selecting(param)
        begin
          fields = command[param]
          Threaded.set_selection(criteria.object_id, fields) unless fields.blank?
          yield
        ensure
          Threaded.delete_selection(criteria.object_id)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
mongoid-4.0.0.alpha2 lib/mongoid/contextual/command.rb
mongoid-4.0.0.alpha1 lib/mongoid/contextual/command.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/contextual/command.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/contextual/command.rb
mongoid_heroku_stable-4.0.0 lib/mongoid/contextual/command.rb
mongoid_rails4-4.0.0 lib/mongoid/contextual/command.rb