Sha256: b35d9949ff5736d6b1e861a4a53310d65379993a94ea01ef944c0eb264245e0f

Contents?: true

Size: 1.42 KB

Versions: 32

Compression:

Stored size: 1.42 KB

Contents

# encoding: utf-8
module Mongoid

  # 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 = []
    end

    # Get the shard key fields.
    #
    # @note Refactored from using delegate for class load performance.
    #
    # @example Get the shard key fields.
    #   model.shard_key_fields
    #
    # @return [ Array<String> ] The shard key field names.
    def shard_key_fields
      self.class.shard_key_fields
    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
      selector = {}
      shard_key_fields.each do |field|
        selector[field.to_s] = send(field)
      end
      selector
    end

    module ClassMethods

      # 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

32 entries across 32 versions & 2 rubygems

Version Path
mongoid-3.1.7 lib/mongoid/sharding.rb
mongoid-3.1.6 lib/mongoid/sharding.rb
mongoid-3.1.5 lib/mongoid/sharding.rb
mongoid-3.1.4 lib/mongoid/sharding.rb
mongoid-3.1.3 lib/mongoid/sharding.rb
mongoid-3.1.2 lib/mongoid/sharding.rb
mongoid-3.0.23 lib/mongoid/sharding.rb
mongoid-3.1.1 lib/mongoid/sharding.rb
mongoid-3.1.0 lib/mongoid/sharding.rb
mongoid-3.0.22 lib/mongoid/sharding.rb
mongoid-3.0.21 lib/mongoid/sharding.rb
mongoid-3.0.20 lib/mongoid/sharding.rb
mongoid-3.0.19 lib/mongoid/sharding.rb
mongoid-3.0.18 lib/mongoid/sharding.rb
mongoid-3.0.17 lib/mongoid/sharding.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.16/lib/mongoid/sharding.rb
mongoid-3.0.16 lib/mongoid/sharding.rb
mongoid-3.0.15 lib/mongoid/sharding.rb
mongoid-3.0.14 lib/mongoid/sharding.rb
mongoid-3.0.13 lib/mongoid/sharding.rb