module ActiveEnumerable::Order
@private
Public Class Methods
call(args, all)
click to toggle source
# File lib/active_enumerable/order.rb, line 7 def call(args, all) options = args.extract_options! if options.empty? && args.count == 1 all.sort_by { |item| MethodCaller.new(item).call(args.first) } else order_mixed_args(all, args, options) end end
Private Class Methods
asc(r)
click to toggle source
# File lib/active_enumerable/order.rb, line 31 def asc(r) r end
build_order(a, options)
click to toggle source
# File lib/active_enumerable/order.rb, line 23 def build_order(a, options) options.map { |k, v| send(v, MethodCaller.new(a).call(k)) } end
desc(r)
click to toggle source
# File lib/active_enumerable/order.rb, line 27 def desc(r) DESC.new(r) end
order_mixed_args(all, args, options)
click to toggle source
# File lib/active_enumerable/order.rb, line 18 def order_mixed_args(all, args, options) normalized_opt = args.each_with_object({}) { |a, h| h[a] = :asc }.merge(options) # Add non specified direction keys all.sort { |a, b| build_order(a, normalized_opt) <=> build_order(b, normalized_opt) } end