Sha256: 07fb1b05f3db6f902b121df972f10ff045f4aa0a98e689a52ce036beaf3ecce8

Contents?: true

Size: 1.48 KB

Versions: 27

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true
# 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

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/criteria/permission.rb
mongoid-7.3.4 lib/mongoid/criteria/permission.rb
mongoid-7.1.11 lib/mongoid/criteria/permission.rb
mongoid-7.2.6 lib/mongoid/criteria/permission.rb
mongoid-7.3.3 lib/mongoid/criteria/permission.rb
mongoid-7.3.2 lib/mongoid/criteria/permission.rb
mongoid-7.2.5 lib/mongoid/criteria/permission.rb
mongoid-7.1.10 lib/mongoid/criteria/permission.rb
mongoid-7.1.9 lib/mongoid/criteria/permission.rb
mongoid-7.2.4 lib/mongoid/criteria/permission.rb
mongoid-7.3.1 lib/mongoid/criteria/permission.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/criteria/permission.rb
mongoid-7.3.0 lib/mongoid/criteria/permission.rb
mongoid-7.2.3 lib/mongoid/criteria/permission.rb
mongoid-7.1.8 lib/mongoid/criteria/permission.rb
mongoid-7.2.2 lib/mongoid/criteria/permission.rb
mongoid-7.2.1 lib/mongoid/criteria/permission.rb
mongoid-7.1.7 lib/mongoid/criteria/permission.rb
mongoid-7.2.0 lib/mongoid/criteria/permission.rb
mongoid-7.1.6 lib/mongoid/criteria/permission.rb