Sha256: 16d293bddb7032a59022afa003890d0885512da9e4056f196356b5c616f51039

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc

  # This module contains behaviour for adding shard key fields to updates.
  module Sharding
    extend ActiveSupport::Concern

    included do
      cattr_accessor :shard_key_fields
      self.shard_key_fields = []

      delegate :shard_key_fields, :to => "self.class"
    end

    # Get the document selector with the defined shard keys.
    #
    # @example Get the selector for the shard keys.
    #   person.shard_key_selector
    #
    # @return [ Hash ] The shard key selector.
    #
    # @since 2.0.0
    def shard_key_selector
      {}.tap do |selector|
        shard_key_fields.each do |field|
          selector[field.to_s] = send(field)
        end
      end
    end

    module ClassMethods #:nodoc

      # Specifies a shard key with the field(s) specified.
      #
      # @example Specify the shard key.
      #
      #   class Person
      #     include Mongoid::Document
      #     field :first_name, :type => String
      #     field :last_name, :type => String
      #
      #     shard_key :first_name, :last_name
      #   end
      #
      # @since 2.0.0
      def shard_key(*names)
        self.shard_key_fields = names
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
mongoid-2.1.7 lib/mongoid/sharding.rb
mongoid-2.1.6 lib/mongoid/sharding.rb
mongoid-2.1.5 lib/mongoid/sharding.rb
mongoid-2.1.4 lib/mongoid/sharding.rb
mongoid-2.1.3 lib/mongoid/sharding.rb
mongoid-2.1.2 lib/mongoid/sharding.rb
mongoid-2.1.1 lib/mongoid/sharding.rb
mongoid-2.1.0 lib/mongoid/sharding.rb
mongoid-braxton-2.0.2 lib/mongoid/sharding.rb
mongoid-2.0.2 lib/mongoid/sharding.rb
mongoid-2.0.1 lib/mongoid/sharding.rb
mongoid-2.0.0 lib/mongoid/sharding.rb
mongoid-2.0.0.rc.8 lib/mongoid/sharding.rb