Class: Deli::Adapters::ActiveRecord::Query
- Defined in:
- lib/deli/adapters/active_record.rb
Instance Attribute Summary
Attributes inherited from Query
Instance Method Summary collapse
-
#render(params) ⇒ Hash
Converts request parameters into an options Hash for ActiveRecord finder methods.# Outputs a query hash for Mongoid.
Methods inherited from Query
#append_join, build_query, #conditions, #conditions?, #default_sort, #find, #initialize, #joins, #matching, #parse, parse_query, #parse_query, parse_string, #parse_string, #to_conditions, unescape
Constructor Details
This class inherits a constructor from Deli::Query
Instance Method Details
#render(params) ⇒ Hash
Converts request parameters into an options Hash for ActiveRecord finder methods.# Outputs a query hash for Mongoid.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/deli/adapters/active_record.rb', line 64 def render(params) hash = super hash["sort"] = default_sort if hash["sort"].blank? && default_sort.present? sort = hash.delete("sort") limit = hash.delete("limit") || 20 page = hash.delete("page") || 1 offset = limit.present? && page.present? ? ((page - 1) * limit).to_i : 0 keys = [] values = [] hash.values.collect do |array| keys << array[0] values << array[1..-1] end keys.map! {|i| "(#{i})"} if keys.length > 1 keys = keys.join(" AND ") values.flatten! conditions = [keys, *values] result = {} result[:conditions] = conditions if conditions.present? result[:limit] = limit if limit.present? && limit > 0 result[:offset] = offset if offset.present? && offset > 0 result[:order] = sort if sort.present? result end |