2011-04-09 20:55:28 -04:00
|
|
|
module Ransack
|
|
|
|
module Nodes
|
|
|
|
module Bindable
|
|
|
|
|
|
|
|
attr_accessor :parent, :attr_name
|
|
|
|
|
|
|
|
def attr
|
2014-11-21 14:16:29 -05:00
|
|
|
@attr ||= get_arel_attribute
|
2011-04-10 21:11:28 -04:00
|
|
|
end
|
2011-04-18 14:34:48 -04:00
|
|
|
alias :arel_attribute :attr
|
2011-04-10 21:11:28 -04:00
|
|
|
|
|
|
|
def ransacker
|
2011-04-11 20:07:23 -04:00
|
|
|
klass._ransackers[attr_name]
|
2011-04-11 12:04:31 -04:00
|
|
|
end
|
|
|
|
|
2011-04-09 20:55:28 -04:00
|
|
|
def klass
|
|
|
|
@klass ||= context.klassify(parent)
|
|
|
|
end
|
|
|
|
|
2011-04-18 13:59:47 -04:00
|
|
|
def bound?
|
|
|
|
attr_name.present? && parent.present?
|
|
|
|
end
|
|
|
|
|
2011-04-09 20:55:28 -04:00
|
|
|
def reset_binding!
|
|
|
|
@parent = @attr_name = @attr = @klass = nil
|
|
|
|
end
|
|
|
|
|
2014-11-21 14:16:29 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_arel_attribute
|
|
|
|
if ransacker
|
|
|
|
ransacker.attr_from(self)
|
|
|
|
else
|
|
|
|
context.table_for(parent)[attr_name]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-09 20:55:28 -04:00
|
|
|
end
|
|
|
|
end
|
2014-11-21 14:16:29 -05:00
|
|
|
end
|