Class: Rails::Surrender::SortBuilder
- Inherits:
-
Object
- Object
- Rails::Surrender::SortBuilder
- Defined in:
- lib/rails/surrender/helpers/sort_builder.rb
Overview
apply sort directives to the given resource, based on the given sort controls
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#sort ⇒ Object
readonly
Returns the value of attribute sort.
Instance Method Summary collapse
- #build! ⇒ Object
-
#initialize(resource:, sort:) ⇒ SortBuilder
constructor
A new instance of SortBuilder.
Constructor Details
#initialize(resource:, sort:) ⇒ SortBuilder
Returns a new instance of SortBuilder.
9 10 11 12 |
# File 'lib/rails/surrender/helpers/sort_builder.rb', line 9 def initialize(resource:, sort:) @resource = resource @sort = sort end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/rails/surrender/helpers/sort_builder.rb', line 7 def resource @resource end |
#sort ⇒ Object (readonly)
Returns the value of attribute sort.
7 8 9 |
# File 'lib/rails/surrender/helpers/sort_builder.rb', line 7 def sort @sort end |
Instance Method Details
#build! ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rails/surrender/helpers/sort_builder.rb', line 14 def build! return resource unless resource.is_a? ActiveRecord::Relation return resource_attribute_order if resource_has_attribute? return scope_method_order if resource_has_scope_method? return association_attribute_order if resource_has_association_with_attribute? raise Error, I18n.t('surrender.error.query_string.sort.invalid_column', param: sort.request) end |