Sha256: 98ae5469337acd7389b9b35846562dba94bd8a218c1f760295293e598a4ddd95

Contents?: true

Size: 897 Bytes

Versions: 2

Compression:

Stored size: 897 Bytes

Contents

module Sunspot
  module DSL #:nodoc:
    # 
    # 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::Query::Restriction.names.each do |class_name|
        method_name = Util.snake_case(class_name.to_s)
        module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
          def #{method_name}(value)
            @query.add_restriction(@field_name, Sunspot::Query::Restriction::#{class_name}, value, @negative)
          end
        RUBY
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
benjaminkrause-sunspot-0.9.7 lib/sunspot/dsl/restriction.rb
benjaminkrause-sunspot-0.9.8 lib/sunspot/dsl/restriction.rb