Class: Friendly::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters, uuid_klass = UUID) ⇒ Query

Returns a new instance of Query.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/friendly/query.rb', line 7

def initialize(parameters, uuid_klass = UUID)
  @uuid_klass = uuid_klass
  @conditions = parameters.reject { |k,v| k.to_s =~ /!$/ }
  @page       = (parameters[:page!] || 1).to_i
  
  [:per_page!, :limit!, :offset!, :order!, :preserve_order!].each do |p|
    instance_variable_set("@#{p.to_s.gsub(/!/, '')}", parameters[p])
  end

  handle_pagination if per_page
  convert_ids_to_uuids
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



3
4
5
# File 'lib/friendly/query.rb', line 3

def conditions
  @conditions
end

#limitObject (readonly)

Returns the value of attribute limit.



3
4
5
# File 'lib/friendly/query.rb', line 3

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



3
4
5
# File 'lib/friendly/query.rb', line 3

def offset
  @offset
end

#orderObject (readonly)

Returns the value of attribute order.



3
4
5
# File 'lib/friendly/query.rb', line 3

def order
  @order
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/friendly/query.rb', line 3

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



3
4
5
# File 'lib/friendly/query.rb', line 3

def per_page
  @per_page
end

#preserve_orderObject (readonly)

Returns the value of attribute preserve_order.



3
4
5
# File 'lib/friendly/query.rb', line 3

def preserve_order
  @preserve_order
end

#uuid_klassObject (readonly)

Returns the value of attribute uuid_klass.



3
4
5
# File 'lib/friendly/query.rb', line 3

def uuid_klass
  @uuid_klass
end

Instance Method Details

#offset?Boolean

Returns:



24
25
26
# File 'lib/friendly/query.rb', line 24

def offset?
  offset
end

#preserve_order?Boolean

Returns:



20
21
22
# File 'lib/friendly/query.rb', line 20

def preserve_order?
  preserve_order
end