diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-02-13 12:44:37 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-02-13 12:44:37 +0900 |
commit | bbf1f152644177774710c52a230813e7d06935df (patch) | |
tree | c82c3c8180cd4e0f052acde12cd32d6479abd21b /activerecord/lib/active_record | |
parent | 22ca710f20c3c656811df006cbf1f4dbc359f7a6 (diff) | |
download | rails-bbf1f152644177774710c52a230813e7d06935df.tar.gz rails-bbf1f152644177774710c52a230813e7d06935df.tar.bz2 rails-bbf1f152644177774710c52a230813e7d06935df.zip |
Refactor `except_predicates_and_binds` to avoid `tap`
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/where_clause.rb | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/relation/where_clause.rb b/activerecord/lib/active_record/relation/where_clause.rb index e862a9048e..e550fcf7ae 100644 --- a/activerecord/lib/active_record/relation/where_clause.rb +++ b/activerecord/lib/active_record/relation/where_clause.rb @@ -134,20 +134,23 @@ module ActiveRecord binds_index = 0 predicates = self.predicates.reject do |node| - case node - 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 - binds_contains = node.grep(Arel::Nodes::BindParam).size - subrelation = (node.left.kind_of?(Arel::Attributes::Attribute) ? node.left : node.right) - columns.include?(subrelation.name.to_s) - end.tap do |except| - if except && binds_contains > 0 - (binds_index...(binds_index + binds_contains)).each do |i| - except_binds[i] = true - end - - binds_index += binds_contains + except = \ + case node + 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 + binds_contains = node.grep(Arel::Nodes::BindParam).size + subrelation = (node.left.kind_of?(Arel::Attributes::Attribute) ? node.left : node.right) + columns.include?(subrelation.name.to_s) end + + if except && binds_contains > 0 + (binds_index...(binds_index + binds_contains)).each do |i| + except_binds[i] = true + end + + binds_index += binds_contains end + + except end binds = self.binds.reject.with_index do |_, i| |