1
0
Fork 0
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:
Yash Ladha 2020-03-10 15:35:07 +05:30
parent 1ef8c60dfc
commit bc95efa7c2
No known key found for this signature in database
GPG key ID: C2BEEFCCB74D6EF0
2 changed files with 10 additions and 5 deletions

View file

@ -51,11 +51,8 @@ module Arel
when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality,
Arel::Nodes::NotEqual, Arel::Nodes::LessThan, Arel::Nodes::LessThanOrEqual, Arel::Nodes::NotEqual, Arel::Nodes::LessThan, Arel::Nodes::LessThanOrEqual,
Arel::Nodes::GreaterThan, Arel::Nodes::GreaterThanOrEqual Arel::Nodes::GreaterThan, Arel::Nodes::GreaterThanOrEqual
if value.left.is_a?(Arel::Attributes::Attribute) attribute_value = value.detect_attribute
yield value.left yield attribute_value if attribute_value
elsif value.right.is_a?(Arel::Attributes::Attribute)
yield value.right
end
when Arel::Nodes::Or when Arel::Nodes::Or
fetch_attribute(value.left, &block) && fetch_attribute(value.right, &block) fetch_attribute(value.left, &block) && fetch_attribute(value.right, &block)
when Arel::Nodes::Grouping when Arel::Nodes::Grouping

View file

@ -11,6 +11,14 @@ module Arel # :nodoc: all
@right = right @right = right
end 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) def initialize_copy(other)
super super
@left = @left.clone if @left @left = @left.clone if @left