Module: RestfulQuery::CanQuery::MacroMethods

Defined in:
lib/restful_query/can_query.rb

Instance Method Summary collapse

Instance Method Details

#can_query(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/restful_query/can_query.rb', line 9

def can_query(options = {})
  @include       = options.delete(:include) || []
  @query_options = options
  @can_query     = true
  module_eval do
    def self.restful_query_parser(query_hash, options = {})
      RestfulQuery::Parser.new(query_hash, @query_options.merge(options))
    end
    
    named_scope :restful_query, lambda {|query_hash| 
      parser = self.restful_query_parser(query_hash)
      query_hash = {}
      query_hash[:conditions] = parser.to_conditions_array if parser.has_conditions?
      query_hash[:include]    = @include if @include && !@include.empty?
      query_hash[:order]      = parser.sort_sql if parser.has_sort?
      logger.info 'Rest query:' + query_hash.inspect
      query_hash
    }
  end
end

#can_query?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/restful_query/can_query.rb', line 30

def can_query?
  @can_query
end