Class: Golden::QueryForm
- Inherits:
-
ApplicationForm
- Object
- ApplicationForm
- Golden::QueryForm
- Defined in:
- lib/golden/objects/query/query_form.rb
Constant Summary
Constants included from BooleanAccessor
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#page ⇒ Object
Returns the value of attribute page.
-
#per ⇒ Object
Returns the value of attribute per.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#sort ⇒ Object
Returns the value of attribute sort.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params, accessors = {}) ⇒ QueryForm
constructor
A new instance of QueryForm.
- #save ⇒ Object
Methods included from DateTimeAccessor
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
#mode ⇒ Object
Returns the value of attribute mode.
20 21 22 |
# File 'lib/golden/objects/query/query_form.rb', line 20 def mode @mode end |
#page ⇒ Object
Returns the value of attribute page.
19 20 21 |
# File 'lib/golden/objects/query/query_form.rb', line 19 def page @page end |
#per ⇒ Object
Returns the value of attribute per.
19 20 21 |
# File 'lib/golden/objects/query/query_form.rb', line 19 def per @per end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
18 19 20 |
# File 'lib/golden/objects/query/query_form.rb', line 18 def result @result end |
#sort ⇒ Object
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
.attributes ⇒ Object
6 7 8 |
# File 'lib/golden/objects/query/query_form.rb', line 6 def attributes accessor_attributes end |
.permits ⇒ Object
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
#save ⇒ Object
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 |