Skip to content

Commit

Permalink
Fix usage of strange ordering lists, e.g. [:name, [:age, :desc]]
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Aug 26, 2024
1 parent 9bee733 commit e3bc8b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.23.3

* Fix usage of ordering strange mixes, such as `[:name, [:age, :desc]]`
that were supported until 0.22.0

## 0.23.2 - 2024-07-09

* `transform` (`TupleTransformer`, actually) now support any Callable
Expand Down
4 changes: 1 addition & 3 deletions lib/bmg/support/ordering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ class Attributes
def initialize(attrs)
@attrs = if attrs.empty?
[]
elsif attrs.first.is_a?(Symbol)
attrs.map{|a| [a, :asc] }
else
attrs
attrs.map{|a| a.is_a?(Symbol) ? [a, :asc] : a }
end
end
attr_reader :attrs
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/support/test_ordering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module Bmg
expect(o.send(:to_a)).to eql([[:name, :asc],[:id, :asc]])
end

it 'supports a strange mix (for backward compat reasons)' do
o = Ordering.new([:name, [:id, :desc]])
expect(o.send(:to_a)).to eql([[:name, :asc],[:id, :desc]])
end

it 'supports a comparator' do
comparator = ->(t1,t2){ 1 }
o = Ordering.new(comparator)
Expand Down

0 comments on commit e3bc8b2

Please sign in to comment.