Sha256: 6caf8b44e70b464a455350d0aeec5920b5e02e746abffcc494ab46ee7e2f2aa3

Contents?: true

Size: 1.45 KB

Versions: 67

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8
module Mongoid
  class Criteria
    module Permission

      [:all,
       :all_in,
       :and,
       :all_of,
       :between,
       :elem_match,
       :exists,
       :gt,
       :gte,
       :in,
       :any_in,
       :lt,
       :lte,
       :max_distance,
       :mod,
       :ne,
       :excludes,
       :near,
       :near_sphere,
       :nin,
       :not_in,
       :nor,
       :negating?,
       :not,
       :or,
       :any_of,
       :with_size,
       :with_type,
       :where,
       :within_box,
       :within_circle,
       :within_polygon,
       :within_spherical_circle
      ].each do |method|
        define_method(method) do |*criteria|
          raise Errors::CriteriaNotPermitted.new(klass, method, criteria) unless should_permit?(criteria)
          super(*criteria)
        end
      end

      private

      # Ensure that the criteria are permitted.
      #
      # @example Ignoring ActionController::Parameters
      #   should_permit?({_id: ActionController::Parameters.new("$size" => 1)})
      #
      # @api private
      #
      # @param [ Object ] criteria
      # @return [ Boolean ] if should permit
      def should_permit?(criteria)
        if criteria.respond_to?(:permitted?)
          return criteria.permitted?
        elsif criteria.respond_to?(:each)
          criteria.each do |criterion|
            return false unless should_permit?(criterion)
          end
        end

        true
      end
    end
  end
end

Version data entries

67 entries across 62 versions & 3 rubygems

Version Path
mongoid-7.0.13 lib/mongoid/criteria/permission.rb
mongoid-7.0.12 lib/mongoid/criteria/permission.rb
mongoid-6.4.8 lib/mongoid/criteria/permission.rb
mongoid-7.0.11 lib/mongoid/criteria/permission.rb
mongoid-7.0.10 lib/mongoid/criteria/permission.rb
mongoid-6.4.7 lib/mongoid/criteria/permission.rb
mongoid-6.4.5 lib/mongoid/criteria/permission.rb
mongoid-7.0.8 lib/mongoid/criteria/permission.rb
mongoid-7.0.7 lib/mongoid/criteria/permission.rb
mongoid-7.0.6 lib/mongoid/criteria/permission.rb
mongoid-5.4.1 lib/mongoid/criteria/permission.rb
mongoid-7.0.5 lib/mongoid/criteria/permission.rb
mongoid-7.0.4 lib/mongoid/criteria/permission.rb
mongoid-6.4.4 lib/mongoid/criteria/permission.rb
mongoid-7.0.3 lib/mongoid/criteria/permission.rb
mongoid-6.4.2 lib/mongoid/criteria/permission.rb
mongoid-7.0.2 lib/mongoid/criteria/permission.rb
mongoid-7.0.1 lib/mongoid/criteria/permission.rb
mongoid-6.4.1 lib/mongoid/criteria/permission.rb
mongoid-5.4.0 lib/mongoid/criteria/permission.rb