Class: Super::Sort::FormObject
- Inherits:
-
Object
- Object
- Super::Sort::FormObject
- Defined in:
- lib/super/sort.rb
Defined Under Namespace
Classes: Expression
Constant Summary collapse
- DIRECTIONS =
["asc", "desc"]
Instance Attribute Summary collapse
-
#sortable_columns ⇒ Object
readonly
Returns the value of attribute sortable_columns.
Instance Method Summary collapse
- #apply_changes(query) ⇒ Object
- #exprs ⇒ Object
-
#initialize(model:, params:, default:, sortable_columns:) ⇒ FormObject
constructor
A new instance of FormObject.
- #new_expr ⇒ Object
- #persisted? ⇒ Boolean
- #to_partial_path ⇒ Object
Constructor Details
#initialize(model:, params:, default:, sortable_columns:) ⇒ FormObject
Returns a new instance of FormObject.
8 9 10 11 12 13 14 15 |
# File 'lib/super/sort.rb', line 8 def initialize(model:, params:, default:, sortable_columns:) @model = model @params = params.dup @default = default @sortable_columns = sortable_columns.map(&:to_s) @params.permit! end |
Instance Attribute Details
#sortable_columns ⇒ Object (readonly)
Returns the value of attribute sortable_columns.
17 18 19 |
# File 'lib/super/sort.rb', line 17 def sortable_columns @sortable_columns end |
Instance Method Details
#apply_changes(query) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/super/sort.rb', line 59 def apply_changes(query) exprs.each do |expr| query = query.order(expr.a => expr.d) end query end |
#exprs ⇒ Object
23 24 25 |
# File 'lib/super/sort.rb', line 23 def exprs sanitized_expr_params.map { |ordering| Expression.new(**ordering) } end |
#new_expr ⇒ Object
27 28 29 |
# File 'lib/super/sort.rb', line 27 def new_expr Expression.new(a: nil, d: :desc) end |
#persisted? ⇒ Boolean
55 56 57 |
# File 'lib/super/sort.rb', line 55 def persisted? false end |
#to_partial_path ⇒ Object
19 20 21 |
# File 'lib/super/sort.rb', line 19 def to_partial_path "sort" end |