lib/locomotive/steam/adapters/mongodb/query.rb in locomotivecms_steam-1.0.0 vs lib/locomotive/steam/adapters/mongodb/query.rb in locomotivecms_steam-1.0.1

- old
+ new

@@ -23,11 +23,11 @@ end end def order_by(*args) self.tap do - @sort = [*args] + @sort = decode_order_by(*args) end end def only(*args) self.tap do @@ -95,9 +95,28 @@ _criterion.delete(key) _key = _key.to_s.to_sym.public_send(operator.to_sym) _criterion[_key] = value end end + end + end + + def decode_order_by(*spec) + [*spec].compact.map do |arg| + _decode_order_by(arg) + end + end + + def _decode_order_by(arg) + case arg + when String + if arg.include?(',') + _decode_order_by(arg.split(',')) + else + arg.strip.split(/[\s|.]/) + end + when Array then arg.map { |_arg| _decode_order_by(_arg) } + else arg end end end