Class: TypicalSort::Sorter
- Inherits:
-
Object
- Object
- TypicalSort::Sorter
- Defined in:
- lib/typical_sort/sorter.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(records:, definition:, direction:, configuration:) ⇒ Sorter
constructor
A new instance of Sorter.
Constructor Details
#initialize(records:, definition:, direction:, configuration:) ⇒ Sorter
Returns a new instance of Sorter.
10 11 12 13 14 15 |
# File 'lib/typical_sort/sorter.rb', line 10 def initialize(records:, definition:, direction:, configuration:) @records = records @definition = definition @direction = direction.to_sym @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/typical_sort/sorter.rb', line 8 def configuration @configuration end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
8 9 10 |
# File 'lib/typical_sort/sorter.rb', line 8 def definition @definition end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
8 9 10 |
# File 'lib/typical_sort/sorter.rb', line 8 def direction @direction end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
8 9 10 |
# File 'lib/typical_sort/sorter.rb', line 8 def records @records end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/typical_sort/sorter.rb', line 17 def call return records.public_send(definition.name, direction) if definition.scope? resolver = PathResolver.new(records: records, path: definition.key) validate_resolver!(resolver) if resolver.collection_association? || definition.aggregate? AggregateSorter.new( records: records, relation_name: resolver.association_name, reflection: resolver.reflection, column_name: resolver.column_name, direction: direction, definition: definition, configuration: configuration ).call elsif resolver.relation_association? sort_relation_association(resolver) else sort_base_column(resolver.column_name) end end |