Class: Golden::QueryForm

Inherits:
ApplicationForm show all
Defined in:
lib/golden/objects/query/query_form.rb

Constant Summary

Constants included from BooleanAccessor

BooleanAccessor::TRUE_VALUES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DateTimeAccessor

#parse_time

Methods included from ExtendedAttrAccessor

#attributes, #strip_attributes, #strip_attributes!

Constructor Details

#initialize(params, accessors = {}) ⇒ QueryForm

Returns a new instance of QueryForm.



22
23
24
25
26
27
28
29
30
# File 'lib/golden/objects/query/query_form.rb', line 22

def initialize(params, accessors = {})
  @query_params = find_query_from(params)
  assign_attributes(strip_attributes(@query_params))
  assign_attributes(strip_attributes(accessors || {}))
  @per ||= params.dig(:per)
  @page ||= params.dig(:page)
  @sort ||= params.dig(:sort)
  @mode ||= :paginated
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



20
21
22
# File 'lib/golden/objects/query/query_form.rb', line 20

def mode
  @mode
end

#pageObject

Returns the value of attribute page.



19
20
21
# File 'lib/golden/objects/query/query_form.rb', line 19

def page
  @page
end

#perObject

Returns the value of attribute per.



19
20
21
# File 'lib/golden/objects/query/query_form.rb', line 19

def per
  @per
end

#resultObject (readonly)

Returns the value of attribute result.



18
19
20
# File 'lib/golden/objects/query/query_form.rb', line 18

def result
  @result
end

#sortObject

Returns the value of attribute sort.



19
20
21
# File 'lib/golden/objects/query/query_form.rb', line 19

def sort
  @sort
end

Class Method Details

.attributesObject



6
7
8
# File 'lib/golden/objects/query/query_form.rb', line 6

def attributes
  accessor_attributes
end

.permitsObject



10
11
12
13
14
15
# File 'lib/golden/objects/query/query_form.rb', line 10

def permits
  @permits ||= lambda do
    attrs = attributes.clone
    attrs.uniq
  end.call
end

Instance Method Details

#saveObject



32
33
34
35
36
37
# File 'lib/golden/objects/query/query_form.rb', line 32

def save
  return false if invalid?

  query!
  errors.empty?
end