diff options
author | Matthew Draper <matthew@trebex.net> | 2017-12-06 23:22:28 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 23:22:28 +1030 |
commit | aa11ad9129b65e637c05cc4b26a2cbbff6f143c2 (patch) | |
tree | 95e60e1280aec63222856ef4e494947eb0913092 | |
parent | 5f25b0aa7fafc1a91605117f8bce700466e0d663 (diff) | |
parent | ff53df96875de84ee02895772b59448f35a5a0c2 (diff) | |
download | rails-aa11ad9129b65e637c05cc4b26a2cbbff6f143c2.tar.gz rails-aa11ad9129b65e637c05cc4b26a2cbbff6f143c2.tar.bz2 rails-aa11ad9129b65e637c05cc4b26a2cbbff6f143c2.zip |
Merge pull request #449 from kbrock/expr_node
Introduce Expression Node
-rw-r--r-- | lib/arel/nodes.rb | 1 | ||||
-rw-r--r-- | lib/arel/nodes/binary.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/case.rb | 4 | ||||
-rw-r--r-- | lib/arel/nodes/casted.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/delete_statement.rb | 21 | ||||
-rw-r--r-- | lib/arel/nodes/extract.rb | 3 | ||||
-rw-r--r-- | lib/arel/nodes/false.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/function.rb | 4 | ||||
-rw-r--r-- | lib/arel/nodes/grouping.rb | 1 | ||||
-rw-r--r-- | lib/arel/nodes/node_expression.rb | 11 | ||||
-rw-r--r-- | lib/arel/nodes/select_statement.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/terminal.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/true.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/unary.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/unary_operation.rb | 8 | ||||
-rw-r--r-- | test/test_nodes.rb | 1 |
16 files changed, 40 insertions, 28 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index bb8ad6500b..8c6572dd6a 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # node require 'arel/nodes/node' +require 'arel/nodes/node_expression' require 'arel/nodes/select_statement' require 'arel/nodes/select_core' require 'arel/nodes/insert_statement' diff --git a/lib/arel/nodes/binary.rb b/lib/arel/nodes/binary.rb index 3001788774..a86d4e4696 100644 --- a/lib/arel/nodes/binary.rb +++ b/lib/arel/nodes/binary.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Arel module Nodes - class Binary < Arel::Nodes::Node + class Binary < Arel::Nodes::NodeExpression attr_accessor :left, :right def initialize left, right diff --git a/lib/arel/nodes/case.rb b/lib/arel/nodes/case.rb index 1edca40001..50ea1e0be2 100644 --- a/lib/arel/nodes/case.rb +++ b/lib/arel/nodes/case.rb @@ -2,10 +2,6 @@ module Arel module Nodes class Case < Arel::Nodes::Node - include Arel::OrderPredications - include Arel::Predications - include Arel::AliasPredication - attr_accessor :case, :conditions, :default def initialize expression = nil, default = nil diff --git a/lib/arel/nodes/casted.rb b/lib/arel/nodes/casted.rb index 1d7385d01b..f945063dd2 100644 --- a/lib/arel/nodes/casted.rb +++ b/lib/arel/nodes/casted.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Arel module Nodes - class Casted < Arel::Nodes::Node # :nodoc: + class Casted < Arel::Nodes::NodeExpression # :nodoc: attr_reader :val, :attribute def initialize val, attribute @val = val diff --git a/lib/arel/nodes/delete_statement.rb b/lib/arel/nodes/delete_statement.rb index 593ce9bddf..063a5341e5 100644 --- a/lib/arel/nodes/delete_statement.rb +++ b/lib/arel/nodes/delete_statement.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true module Arel module Nodes - class DeleteStatement < Arel::Nodes::Binary + class DeleteStatement < Arel::Nodes::Node + attr_accessor :left, :right attr_accessor :limit alias :relation :left @@ -10,13 +11,27 @@ module Arel alias :wheres= :right= def initialize relation = nil, wheres = [] - super + super() + @left = relation + @right = wheres end def initialize_copy other super - @right = @right.clone + @left = @left.clone if @left + @right = @right.clone if @right + end + + def hash + [self.class, @left, @right].hash + end + + def eql? other + self.class == other.class && + self.left == other.left && + self.right == other.right end + alias :== :eql? end end end diff --git a/lib/arel/nodes/extract.rb b/lib/arel/nodes/extract.rb index 4e797b6770..fdf3004c6a 100644 --- a/lib/arel/nodes/extract.rb +++ b/lib/arel/nodes/extract.rb @@ -2,9 +2,6 @@ module Arel module Nodes class Extract < Arel::Nodes::Unary - include Arel::AliasPredication - include Arel::Predications - attr_accessor :field def initialize expr, field diff --git a/lib/arel/nodes/false.rb b/lib/arel/nodes/false.rb index fb821dd522..58132a2f90 100644 --- a/lib/arel/nodes/false.rb +++ b/lib/arel/nodes/false.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Arel module Nodes - class False < Arel::Nodes::Node + class False < Arel::Nodes::NodeExpression def hash self.class.hash end diff --git a/lib/arel/nodes/function.rb b/lib/arel/nodes/function.rb index b2b89ee9ff..b3bf8f3e51 100644 --- a/lib/arel/nodes/function.rb +++ b/lib/arel/nodes/function.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true module Arel module Nodes - class Function < Arel::Nodes::Node - include Arel::Predications + class Function < Arel::Nodes::NodeExpression include Arel::WindowPredications - include Arel::OrderPredications attr_accessor :expressions, :alias, :distinct def initialize expr, aliaz = nil diff --git a/lib/arel/nodes/grouping.rb b/lib/arel/nodes/grouping.rb index 16911eb3b6..ffe66654ce 100644 --- a/lib/arel/nodes/grouping.rb +++ b/lib/arel/nodes/grouping.rb @@ -2,7 +2,6 @@ module Arel module Nodes class Grouping < Unary - include Arel::Predications end end end diff --git a/lib/arel/nodes/node_expression.rb b/lib/arel/nodes/node_expression.rb new file mode 100644 index 0000000000..c4d4c8f428 --- /dev/null +++ b/lib/arel/nodes/node_expression.rb @@ -0,0 +1,11 @@ +module Arel + module Nodes + class NodeExpression < Arel::Nodes::Node + include Arel::Expressions + include Arel::Predications + include Arel::AliasPredication + include Arel::OrderPredications + include Arel::Math + end + end +end diff --git a/lib/arel/nodes/select_statement.rb b/lib/arel/nodes/select_statement.rb index 641a08405d..79176d4be5 100644 --- a/lib/arel/nodes/select_statement.rb +++ b/lib/arel/nodes/select_statement.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Arel module Nodes - class SelectStatement < Arel::Nodes::Node + class SelectStatement < Arel::Nodes::NodeExpression attr_reader :cores attr_accessor :limit, :orders, :lock, :offset, :with diff --git a/lib/arel/nodes/terminal.rb b/lib/arel/nodes/terminal.rb index 421f039904..3a1cd7f0e1 100644 --- a/lib/arel/nodes/terminal.rb +++ b/lib/arel/nodes/terminal.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Arel module Nodes - class Distinct < Arel::Nodes::Node + class Distinct < Arel::Nodes::NodeExpression def hash self.class.hash end diff --git a/lib/arel/nodes/true.rb b/lib/arel/nodes/true.rb index bb9d8c1414..fdb8ed2095 100644 --- a/lib/arel/nodes/true.rb +++ b/lib/arel/nodes/true.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Arel module Nodes - class True < Arel::Nodes::Node + class True < Arel::Nodes::NodeExpression def hash self.class.hash end diff --git a/lib/arel/nodes/unary.rb b/lib/arel/nodes/unary.rb index a42744b1d5..5711d91dce 100644 --- a/lib/arel/nodes/unary.rb +++ b/lib/arel/nodes/unary.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Arel module Nodes - class Unary < Arel::Nodes::Node + class Unary < Arel::Nodes::NodeExpression attr_accessor :expr alias :value :expr diff --git a/lib/arel/nodes/unary_operation.rb b/lib/arel/nodes/unary_operation.rb index 3c56ef2026..be4e270e76 100644 --- a/lib/arel/nodes/unary_operation.rb +++ b/lib/arel/nodes/unary_operation.rb @@ -3,12 +3,6 @@ module Arel module Nodes class UnaryOperation < Unary - include Arel::Expressions - include Arel::Predications - include Arel::OrderPredications - include Arel::AliasPredication - include Arel::Math - attr_reader :operator def initialize operator, operand @@ -23,4 +17,4 @@ module Arel end end end -end
\ No newline at end of file +end diff --git a/test/test_nodes.rb b/test/test_nodes.rb index bf0082396d..1060f150ff 100644 --- a/test/test_nodes.rb +++ b/test/test_nodes.rb @@ -12,6 +12,7 @@ module Arel node_descendants.unshift k unless k == self end node_descendants.delete(Arel::Nodes::Node) + node_descendants.delete(Arel::Nodes::NodeExpression) bad_node_descendants = node_descendants.reject do |subnode| eqeq_owner = subnode.instance_method(:==).owner |