Sha256: 9c588a882044a5d59b46da3aa5ed48fc6758a346881b277b151091a749003263

Contents?: true

Size: 869 Bytes

Versions: 4

Compression:

Stored size: 869 Bytes

Contents

module Sunspot
  module DSL
    # 
    # This class presents an API for building restrictions in the query DSL. The
    # methods exposed are the snake-cased names of the classes defined in the
    # Restriction module, with the exception of Base and SameAs. All methods
    # take a single argument, which is the value to be applied to the
    # restriction.
    #
    class Restriction
      def initialize(field_name, query, negative)
        @field_name, @query, @negative = field_name, query, negative
      end

      Sunspot::Restriction.names.each do |class_name|
        method_name = Util.snake_case(class_name)
        module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
          def #{method_name}(value)
            @query.add_restriction(@field_name, Sunspot::Restriction::#{class_name}, value, @negative)
          end
        RUBY
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
outoftime-sunspot-0.7.0 lib/sunspot/dsl/scope.rb
outoftime-sunspot-0.7.1 lib/sunspot/dsl/scope.rb
outoftime-sunspot-0.7.2 lib/sunspot/dsl/scope.rb
outoftime-sunspot-0.7.3 lib/sunspot/dsl/scope.rb