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