Class: Ransack::Nodes::Sort

Inherits:
Node
  • Object
show all
Includes:
Bindable
Defined in:
lib/ransack/nodes/sort.rb

Instance Attribute Summary collapse

Attributes included from Bindable

#attr_name, #parent

Attributes inherited from Node

#context

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

#dirObject

Returns the value of attribute dir.



6
7
8
# File 'lib/ransack/nodes/sort.rb', line 6

def dir
  @dir
end

#nameObject

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
14
# File 'lib/ransack/nodes/sort.rb', line 10

def extract(context, str)
  return unless str
  attr, direction = str.split(/\s+/,2)
  self.new(context).build(name: attr, dir: direction)
end

Instance Method Details

#build(params) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/ransack/nodes/sort.rb', line 17

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

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/ransack/nodes/sort.rb', line 27

def valid?
  bound? && attr &&
  context.klassify(parent).ransortable_attributes(context.auth_object)
  .include?(attr_name)
end