Class: Ransack::Nodes::Sort
- Includes:
- Bindable
- Defined in:
- lib/ransack/nodes/sort.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes included from Bindable
Attributes inherited from Node
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Bindable
#attr, #bound?, #klass, #ransacker, #reset_binding!
Methods inherited from Node
i18n_alias, i18n_word, #initialize, #translate
Constructor Details
This class inherits a constructor from Ransack::Nodes::Node
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
6 7 8 |
# File 'lib/ransack/nodes/sort.rb', line 6 def dir @dir end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/ransack/nodes/sort.rb', line 6 def name @name end |
Class Method Details
.extract(context, str) ⇒ Object
10 11 12 13 |
# File 'lib/ransack/nodes/sort.rb', line 10 def extract(context, str) attr, direction = str.split(/\s+/,2) self.new(context).build(:name => attr, :dir => direction) end |
Instance Method Details
#build(params) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/ransack/nodes/sort.rb', line 16 def build(params) params.with_indifferent_access.each do |key, value| if key.match(/^(name|dir)$/) self.send("#{key}=", value) end end self end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/ransack/nodes/sort.rb', line 26 def valid? bound? && attr end |