lib/ransack/nodes/sort.rb in ransack-1.7.0 vs lib/ransack/nodes/sort.rb in ransack-1.8.0
- old
+ new
@@ -1,11 +1,11 @@
module Ransack
module Nodes
class Sort < Node
include Bindable
- attr_reader :name, :dir
+ attr_reader :name, :dir, :ransacker_args
i18n_word :asc, :desc
class << self
def extract(context, str)
return unless str
@@ -14,11 +14,11 @@
end
end
def build(params)
params.with_indifferent_access.each do |key, value|
- if key.match(/^(name|dir)$/)
+ if key.match(/^(name|dir|ransacker_args)$/)
self.send("#{key}=", value)
end
end
self
@@ -30,20 +30,24 @@
.include?(attr_name)
end
def name=(name)
@name = name
- context.bind(self, name) unless name.blank?
+ context.bind(self, name)
end
def dir=(dir)
dir = dir.downcase if dir
@dir =
- if Constants::ASC_DESC.include?(dir)
+ if ['asc'.freeze, 'desc'.freeze].freeze.include?(dir)
dir
else
- Constants::ASC
+ 'asc'.freeze
end
+ end
+
+ def ransacker_args=(ransack_args)
+ @ransacker_args = ransack_args
end
end
end
end