mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
refactor: arel fetch_attribute to get the atrribute node from binary
module. Reason for doing this change is to pull the node specific changes to module itself and to not infer on the attributes, rather than assign responsibility to the member functions to do so.
This commit is contained in:
parent
1ef8c60dfc
commit
bc95efa7c2
2 changed files with 10 additions and 5 deletions
|
@ -51,11 +51,8 @@ module Arel
|
|||
when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality,
|
||||
Arel::Nodes::NotEqual, Arel::Nodes::LessThan, Arel::Nodes::LessThanOrEqual,
|
||||
Arel::Nodes::GreaterThan, Arel::Nodes::GreaterThanOrEqual
|
||||
if value.left.is_a?(Arel::Attributes::Attribute)
|
||||
yield value.left
|
||||
elsif value.right.is_a?(Arel::Attributes::Attribute)
|
||||
yield value.right
|
||||
end
|
||||
attribute_value = value.detect_attribute
|
||||
yield attribute_value if attribute_value
|
||||
when Arel::Nodes::Or
|
||||
fetch_attribute(value.left, &block) && fetch_attribute(value.right, &block)
|
||||
when Arel::Nodes::Grouping
|
||||
|
|
|
@ -11,6 +11,14 @@ module Arel # :nodoc: all
|
|||
@right = right
|
||||
end
|
||||
|
||||
def detect_attribute
|
||||
if self.left.is_a?(Arel::Attributes::Attribute)
|
||||
self.left
|
||||
elsif self.right.is_a?(Arel::Attributes::Attribute)
|
||||
self.right
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_copy(other)
|
||||
super
|
||||
@left = @left.clone if @left
|
||||
|
|
Loading…
Reference in a new issue