Class: Golden::QueryContext
- Inherits:
-
ApplicationContext
- Object
- ApplicationContext
- Golden::QueryContext
- Includes:
- ActiveRecord::Sanitization::ClassMethods
- Defined in:
- lib/golden/objects/query/query_context.rb
Constant Summary
Constants included from BooleanAccessor
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#per ⇒ Object
Returns the value of attribute per.
-
#pluck_fields ⇒ Object
readonly
Returns the value of attribute pluck_fields.
-
#sort_direction ⇒ Object
Returns the value of attribute sort_direction.
-
#sort_field ⇒ Object
Returns the value of attribute sort_field.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(accessors = {}) ⇒ QueryContext
constructor
A new instance of QueryContext.
- #perform(mode = :paginated, pluck: nil) ⇒ Object
- #sort=(values) ⇒ Object
Methods inherited from ApplicationContext
Methods included from DateTimeAccessor
Methods included from ExtendedAttrAccessor
#attributes, #strip_attributes, #strip_attributes!
Constructor Details
#initialize(accessors = {}) ⇒ QueryContext
Returns a new instance of QueryContext.
20 21 22 23 24 |
# File 'lib/golden/objects/query/query_context.rb', line 20 def initialize(accessors = {}) assign_attributes(accessors || {}) @page ||= 1 @per ||= 100 end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
14 15 16 |
# File 'lib/golden/objects/query/query_context.rb', line 14 def page @page end |
#per ⇒ Object
Returns the value of attribute per.
14 15 16 |
# File 'lib/golden/objects/query/query_context.rb', line 14 def per @per end |
#pluck_fields ⇒ Object (readonly)
Returns the value of attribute pluck_fields.
18 19 20 |
# File 'lib/golden/objects/query/query_context.rb', line 18 def pluck_fields @pluck_fields end |
#sort_direction ⇒ Object
Returns the value of attribute sort_direction.
15 16 17 |
# File 'lib/golden/objects/query/query_context.rb', line 15 def sort_direction @sort_direction end |
#sort_field ⇒ Object
Returns the value of attribute sort_field.
15 16 17 |
# File 'lib/golden/objects/query/query_context.rb', line 15 def sort_field @sort_field end |
Class Method Details
.attributes ⇒ Object
6 7 8 9 |
# File 'lib/golden/objects/query/query_context.rb', line 6 def attributes merge_attributes!(:sort) accessor_attributes end |
Instance Method Details
#perform(mode = :paginated, pluck: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/golden/objects/query/query_context.rb', line 26 def perform(mode = :paginated, pluck: nil) @plucking = pluck.present? @pluck_fields = pluck send("find_#{mode}") end |
#sort=(values) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/golden/objects/query/query_context.rb', line 32 def sort=(values) return if values.blank? field, direction = values.to_s.split(',') @sort_field = field.presence&.to_sym @sort_direction = direction.presence&.to_sym end |