2011-03-31 00:31:39 +00:00
|
|
|
module Ransack
|
|
|
|
module Nodes
|
|
|
|
class Attribute < Node
|
2011-04-10 00:55:28 +00:00
|
|
|
include Bindable
|
|
|
|
|
|
|
|
attr_reader :name
|
|
|
|
|
2014-05-01 13:55:39 +00:00
|
|
|
delegate :blank?, :present?, :==, :to => :name
|
|
|
|
delegate :engine, :to => :context
|
2011-03-31 00:31:39 +00:00
|
|
|
|
|
|
|
def initialize(context, name = nil)
|
|
|
|
super(context)
|
|
|
|
self.name = name unless name.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def name=(name)
|
|
|
|
@name = name
|
2011-04-10 00:55:28 +00:00
|
|
|
context.bind(self, name) unless name.blank?
|
2011-03-31 00:31:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
2013-12-07 00:51:55 +00:00
|
|
|
bound? && attr &&
|
2013-12-15 18:27:50 +00:00
|
|
|
context.klassify(parent).ransackable_attributes(context.auth_object)
|
|
|
|
.include?(attr_name)
|
2011-04-10 00:55:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
if ransacker
|
2011-04-12 00:07:23 +00:00
|
|
|
return ransacker.type
|
2011-04-10 00:55:28 +00:00
|
|
|
else
|
2011-04-18 18:34:48 +00:00
|
|
|
context.type_for(self)
|
2011-04-10 00:55:28 +00:00
|
|
|
end
|
2011-03-31 00:31:39 +00: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-11 01:11:28 +00:00
|
|
|
|
2012-08-07 15:07:42 +00:00
|
|
|
def inspect
|
|
|
|
"Attribute <#{name}>"
|
|
|
|
end
|
|
|
|
|
2011-03-31 00:31:39 +00:00
|
|
|
end
|
|
|
|
end
|
2013-10-29 23:16:49 +00:00
|
|
|
end
|