Sha256: 594cf60033f1956541bc495152b92589d80ac8149cea9151b61a372af5327246

Contents?: true

Size: 1.25 KB

Versions: 56

Compression:

Stored size: 1.25 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Hash #:nodoc:

      # Expands complex criterion into mongodb selectors.
      module CriteriaHelpers

        # Expand the complex criteria into a MongoDB compliant selector hash.
        #
        # @example Convert the criterion.
        #   {}.expand_complex_criteria
        #
        # @return [ Hash ] The mongo selector.
        #
        # @since 1.0.0
        def expand_complex_criteria
          {}.tap do |hsh|
            each_pair do |k,v|
              if k.respond_to?(:key) && k.respond_to?(:to_mongo_query)
                hsh[k.key] ||= {}
                v = v.expand_complex_criteria if v.is_a?(::Hash)
                hsh[k.key].merge!(k.to_mongo_query(v))
              else
                hsh[k] = v
              end
            end
          end
        end

        # Get the id attribute from this hash, whether it's prefixed with an
        # underscore or is a symbol.
        #
        # @example Extract the id.
        #   { :_id => 1 }.extract_id
        #
        # @return [ Object ] The value of the id.
        #
        # @since 2.3.2
        def extract_id
          self["id"] || self["_id"] || self[:id] || self[:_id]
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 3 rubygems

Version Path
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.5.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.4.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.4.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.4.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.3.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.3.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.3.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.3.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.3.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/hash/criteria_helpers.rb