Sha256: 92fc9b275e8a66e9043fa448ff9cececdc3d0e87d5510ab2a7e424eea416290a

Contents?: true

Size: 1.35 KB

Versions: 104

Compression:

Stored size: 1.35 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
                v.map!{|e| e.is_a?(::Hash) ? e.expand_complex_criteria : e } if v.is_a?(::Array)
                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

104 entries across 58 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/hash/criteria_helpers.rb
mongoid-2.8.1 lib/mongoid/extensions/hash/criteria_helpers.rb
mongoid-2.8.0 lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/hash/criteria_helpers.rb
mongoid-2.7.1 lib/mongoid/extensions/hash/criteria_helpers.rb
mongoid-2.7.0 lib/mongoid/extensions/hash/criteria_helpers.rb
mongoid-2.6.0 lib/mongoid/extensions/hash/criteria_helpers.rb
mongoid-2.5.2 lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.6.9 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/hash/criteria_helpers.rb
classiccms-0.6.9 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/hash/criteria_helpers.rb