activerecord-hackery--ransack/lib/ransack/nodes/attribute.rb

49 lines
850 B
Ruby
Raw Normal View History

2011-03-31 00:31:39 +00:00
module Ransack
module Nodes
class Attribute < Node
include Bindable
attr_reader :name
2011-04-11 16:04:31 +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
context.bind(self, name) unless name.blank?
2011-03-31 00:31:39 +00:00
end
def valid?
bound? && attr
end
def type
if ransacker
return ransacker.type
else
context.type_for(self)
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-03-31 00:31:39 +00:00
end
end
end