Module: LinkedRails::Collection::Sortable
- Included in:
- LinkedRails::Collection
- Defined in:
- app/models/linked_rails/collection/sortable.rb
Instance Attribute Summary collapse
-
#sort ⇒ Object
Returns the value of attribute sort.
- #sort_options ⇒ Object
Instance Method Summary collapse
- #default_before_value ⇒ Object
- #parsed_sort_values ⇒ Object
- #primary_key_sorting ⇒ Object
- #sorted? ⇒ Boolean
- #sorted_association(scope) ⇒ Object
- #sortings ⇒ Object
Instance Attribute Details
#sort ⇒ Object
Returns the value of attribute sort.
6 7 8 |
# File 'app/models/linked_rails/collection/sortable.rb', line 6 def sort @sort end |
#sort_options ⇒ Object
31 32 33 |
# File 'app/models/linked_rails/collection/sortable.rb', line 31 def || association_class.try(:sort_options, self) end |
Instance Method Details
#default_before_value ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'app/models/linked_rails/collection/sortable.rb', line 9 def default_before_value sortings.map do |sorting| { key: sorting.key, value: sorting.default_value } end end |
#parsed_sort_values ⇒ Object
18 19 20 |
# File 'app/models/linked_rails/collection/sortable.rb', line 18 def parsed_sort_values sortings.map(&:sort_value) end |
#primary_key_sorting ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/models/linked_rails/collection/sortable.rb', line 22 def primary_key_sorting [ { key: Vocab.ontola[:primaryKey], direction: :asc } ] end |
#sorted? ⇒ Boolean
39 40 41 |
# File 'app/models/linked_rails/collection/sortable.rb', line 39 def sorted? sort.present? end |
#sorted_association(scope) ⇒ Object
35 36 37 |
# File 'app/models/linked_rails/collection/sortable.rb', line 35 def sorted_association(scope) scope.respond_to?(:reorder) ? scope.reorder(parsed_sort_values) : scope end |
#sortings ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/linked_rails/collection/sortable.rb', line 43 def sortings @sortings ||= LinkedRails.collection_sorting_class.from_array( association_class, (sort || default_sortings) + primary_key_sorting, self ) end |