mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
1abf8f6086
since Rails 3.x stills supports Ruby 1.8.7 as per http://guides.rubyonrails.org/v3.2.17/getting_started.html: “Ruby language version 1.8.7 or higher.”
55 lines
1,019 B
Ruby
55 lines
1,019 B
Ruby
module Ransack
|
|
module Nodes
|
|
class Attribute < Node
|
|
include Bindable
|
|
|
|
attr_reader :name
|
|
|
|
delegate :blank?, :present?, :==, :to => :name
|
|
delegate :engine, :to => :context
|
|
|
|
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?
|
|
end
|
|
|
|
def valid?
|
|
bound? && attr &&
|
|
context.klassify(parent).ransackable_attributes(context.auth_object)
|
|
.include?(attr_name)
|
|
end
|
|
|
|
def type
|
|
if ransacker
|
|
return ransacker.type
|
|
else
|
|
context.type_for(self)
|
|
end
|
|
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
|
|
|
|
def inspect
|
|
"Attribute <#{name}>"
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|