Class: Ransack::Nodes::Attribute

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

Instance Attribute Summary collapse

Attributes included from Bindable

#attr_name, #parent

Attributes inherited from Node

#context

Instance Method Summary collapse

Methods included from Bindable

#attr, #bound?, #klass, #ransacker, #reset_binding!

Methods inherited from Node

i18n_alias, i18n_word, #translate

Constructor Details

#initialize(context, name = nil) ⇒ Attribute


11
12
13
14
# File 'lib/ransack/nodes/attribute.rb', line 11

def initialize(context, name = nil)
  super(context)
  self.name = name unless name.blank?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


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

def name
  @name
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==


35
36
37
38
# File 'lib/ransack/nodes/attribute.rb', line 35

def eql?(other)
  self.class == other.class &&
  self.name == other.name
end

#hashObject


41
42
43
# File 'lib/ransack/nodes/attribute.rb', line 41

def hash
  self.name.hash
end

#inspectObject


49
50
51
# File 'lib/ransack/nodes/attribute.rb', line 49

def inspect
  "Attribute <#{name}>"
end

#persisted?Boolean


45
46
47
# File 'lib/ransack/nodes/attribute.rb', line 45

def persisted?
  false
end

#typeObject


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

def type
  if ransacker
    return ransacker.type
  else
    context.type_for(self)
  end
end

#valid?Boolean


21
22
23
24
25
# File 'lib/ransack/nodes/attribute.rb', line 21

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