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, ransacker_args = []) ⇒ Attribute

Returns a new instance of Attribute.



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

def initialize(context, name = nil, ransacker_args = [])
  super(context)
  self.name = name unless name.blank?
  @ransacker_args = ransacker_args
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

#ransacker_argsObject (readonly)

Returns the value of attribute ransacker_args.



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

def ransacker_args
  @ransacker_args
end

Instance Method Details

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

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  self.name.hash
end

#inspectObject



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

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

#persisted?Boolean

Returns:

  • (Boolean)


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

def persisted?
  false
end

#typeObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

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