Sha256: 43486437d906bca382e6e8abf88ad4b405e2c5aec064bd3038c2cb37524086bd

Contents?: true

Size: 835 Bytes

Versions: 1

Compression:

Stored size: 835 Bytes

Contents

module Searchgasm
  module Shared
    # = Searchgasm Searching
    #
    # Implements searching functionality for searchgasm. Searchgasm::Search::Base and Searchgasm::Conditions::Base can both search and include
    # this module.
    module Searching
      # Use these methods just like you would in ActiveRecord
      SEARCH_METHODS = [:all, :average, :calculate, :count, :find, :first, :maximum, :minimum, :sum]
      
      # Setup methods for searching
      SEARCH_METHODS.each do |method|
        class_eval <<-"end_eval", __FILE__, __LINE__
          def #{method}(*args)
            options = args.extract_options!
            klass.send(:with_scope, :find => options) do
              args << sanitize(:#{method})
              klass.#{method}(*args)
            end
          end
        end_eval
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
searchgasm-1.0.3 lib/searchgasm/shared/searching.rb