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

#associated_collection?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ransack/nodes/attribute.rb', line 27

def associated_collection?
  parent.respond_to?(:reflection) && parent.reflection.collection?
end

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

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  self.name.hash
end

#inspectObject



53
54
55
# File 'lib/ransack/nodes/attribute.rb', line 53

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

#persisted?Boolean

Returns:

  • (Boolean)


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

def persisted?
  false
end

#typeObject



31
32
33
34
35
36
37
# File 'lib/ransack/nodes/attribute.rb', line 31

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

#valid?Boolean

Returns:

  • (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.split('.').last)
end