Module: LinkedRails::Collection::Sortable
- Included in:
- LinkedRails::Collection
- Defined in:
- app/models/linked_rails/collection/sortable.rb
Instance Attribute Summary collapse
- #default_sortings ⇒ Object
-
#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
#default_sortings ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/models/linked_rails/collection/sortable.rb', line 18 def default_sortings opts = @default_sortings || association_class.try(:default_sortings) || [{key: Vocab.schema.dateCreated, direction: :desc}] opts.respond_to?(:call) ? opts.call(parent) : opts end |
#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
39 40 41 |
# File 'app/models/linked_rails/collection/sortable.rb', line 39 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
26 27 28 |
# File 'app/models/linked_rails/collection/sortable.rb', line 26 def parsed_sort_values sortings.map(&:sort_value) end |
#primary_key_sorting ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/models/linked_rails/collection/sortable.rb', line 30 def primary_key_sorting [ { key: Vocab.ontola[:primaryKey], direction: :asc } ] end |
#sorted? ⇒ Boolean
47 48 49 |
# File 'app/models/linked_rails/collection/sortable.rb', line 47 def sorted? sort.present? end |
#sorted_association(scope) ⇒ Object
43 44 45 |
# File 'app/models/linked_rails/collection/sortable.rb', line 43 def sorted_association(scope) scope.respond_to?(:reorder) ? scope.reorder(parsed_sort_values) : scope end |
#sortings ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/models/linked_rails/collection/sortable.rb', line 51 def sortings @sortings ||= LinkedRails.collection_sorting_class.from_array( association_class, (sort || default_sortings) + primary_key_sorting, self ) end |