Class: TypicalSort::SortSet
- Inherits:
-
Object
- Object
- TypicalSort::SortSet
- Defined in:
- lib/typical_sort/sort_set.rb
Instance Attribute Summary collapse
-
#default_attribute ⇒ Object
readonly
Returns the value of attribute default_attribute.
-
#default_direction ⇒ Object
readonly
Returns the value of attribute default_direction.
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
Instance Method Summary collapse
- #default(attribute, direction = nil) ⇒ Object
- #fetch(attribute) ⇒ Object
-
#initialize ⇒ SortSet
constructor
A new instance of SortSet.
- #keys ⇒ Object
- #sort(attribute, aggregate: nil, nulls: nil, scope: false) ⇒ Object
Constructor Details
#initialize ⇒ SortSet
Returns a new instance of SortSet.
9 10 11 |
# File 'lib/typical_sort/sort_set.rb', line 9 def initialize @definitions = {} end |
Instance Attribute Details
#default_attribute ⇒ Object (readonly)
Returns the value of attribute default_attribute.
7 8 9 |
# File 'lib/typical_sort/sort_set.rb', line 7 def default_attribute @default_attribute end |
#default_direction ⇒ Object (readonly)
Returns the value of attribute default_direction.
7 8 9 |
# File 'lib/typical_sort/sort_set.rb', line 7 def default_direction @default_direction end |
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
7 8 9 |
# File 'lib/typical_sort/sort_set.rb', line 7 def definitions @definitions end |
Instance Method Details
#default(attribute, direction = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/typical_sort/sort_set.rb', line 13 def default(attribute, direction = nil) @default_attribute = attribute @default_direction = direction&.to_sym sort(attribute) unless definitions.key?(attribute.to_s) end |
#fetch(attribute) ⇒ Object
24 25 26 |
# File 'lib/typical_sort/sort_set.rb', line 24 def fetch(attribute) definitions[attribute.to_s] end |
#keys ⇒ Object
28 29 30 |
# File 'lib/typical_sort/sort_set.rb', line 28 def keys definitions.keys end |
#sort(attribute, aggregate: nil, nulls: nil, scope: false) ⇒ Object
19 20 21 22 |
# File 'lib/typical_sort/sort_set.rb', line 19 def sort(attribute, aggregate: nil, nulls: nil, scope: false) definition = SortDefinition.new(name: attribute.to_s, aggregate: aggregate&.to_sym, nulls: nulls&.to_sym, scope: scope) definitions[definition.key] = definition end |