2011-03-30 20:31:39 -04:00
|
|
|
module Ransack
|
|
|
|
module Nodes
|
|
|
|
class Attribute < Node
|
2011-04-09 20:55:28 -04:00
|
|
|
include Bindable
|
|
|
|
|
|
|
|
attr_reader :name
|
|
|
|
|
2013-08-12 04:27:50 -04:00
|
|
|
delegate :blank?, :present?, :==, to: :name
|
|
|
|
delegate :engine, to: :context
|
2011-03-30 20:31:39 -04:00
|
|
|
|
|
|
|
def initialize(context, name = nil)
|
|
|
|
super(context)
|
|
|
|
self.name = name unless name.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def name=(name)
|
|
|
|
@name = name
|
2011-04-09 20:55:28 -04:00
|
|
|
context.bind(self, name) unless name.blank?
|
2011-03-30 20:31:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
2013-12-06 19:51:55 -05:00
|
|
|
bound? && attr &&
|
|
|
|
context.klassify(parent).ransackable_attributes(context.auth_object)
|
|
|
|
.include?(attr_name)
|
2011-04-09 20:55:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
if ransacker
|
2011-04-11 20:07:23 -04:00
|
|
|
return ransacker.type
|
2011-04-09 20:55:28 -04:00
|
|
|
else
|
2011-04-18 14:34:48 -04:00
|
|
|
context.type_for(self)
|
2011-04-09 20:55:28 -04:00
|
|
|
end
|
2011-03-30 20:31:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def eql?(other)
|
|
|
|
self.class == other.class &&
|
|
|
|
self.name == other.name
|
|
|
|
end
|
|
|
|
alias :== :eql?
|
|
|
|
|
|
|
|
def hash
|
|
|
|
self.name.hash
|
|
|
|
end
|
|
|
|
|
|
|
|
def persisted?
|
|
|
|
false
|
|
|
|
end
|
2011-04-10 21:11:28 -04:00
|
|
|
|
2012-08-07 11:07:42 -04:00
|
|
|
def inspect
|
|
|
|
"Attribute <#{name}>"
|
|
|
|
end
|
|
|
|
|
2011-03-30 20:31:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|