diff --git a/Gemfile b/Gemfile index dda44db5..d6d0263d 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,8 @@ git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end +gem 'sorbet' +gem 'sorbet-runtime' + # Specify your gem's dependencies in arel_toolkit.gemspec gemspec diff --git a/Gemfile.lock b/Gemfile.lock index 5755a94a..531c8bff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -152,6 +152,10 @@ GEM hirb simplecov simplecov-html (0.10.2) + sorbet (0.4.4399) + sorbet-static (= 0.4.4399) + sorbet-runtime (0.4.4399) + sorbet-static (0.4.4399-universal-darwin-14) thor (0.20.3) thread_safe (0.3.6) tzinfo (1.2.5) @@ -181,6 +185,8 @@ DEPENDENCIES rubocop (~> 0.69) simplecov (~> 0.16.1) simplecov-console (~> 0.4.2) + sorbet + sorbet-runtime BUNDLED WITH 2.0.1 diff --git a/lib/arel/extensions.rb b/lib/arel/extensions.rb index c44e0010..3c6d0f0f 100644 --- a/lib/arel/extensions.rb +++ b/lib/arel/extensions.rb @@ -1,3 +1,4 @@ +# typed: strict require 'arel/extensions/unknown' require 'arel/extensions/time_with_precision' require 'arel/extensions/current_time' @@ -98,4 +99,4 @@ module Arel module Extensions end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/absolute.rb b/lib/arel/extensions/absolute.rb index 062bcc73..61283551 100644 --- a/lib/arel/extensions/absolute.rb +++ b/lib/arel/extensions/absolute.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-math.html class Absolute < Arel::Nodes::UnaryOperation + sig { params(operand: Integer).void } def initialize(operand) super('@', operand) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/all.rb b/lib/arel/extensions/all.rb index 755e7f39..c3b5f90d 100644 --- a/lib/arel/extensions/all.rb +++ b/lib/arel/extensions/all.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class All < Arel::Nodes::Unary module Visitors class ToSql + sig { params(o: Arel::Nodes::All, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_All(o, collector) collector << 'ALL(' visit o.expr, collector @@ -20,4 +22,4 @@ def visit_Arel_Nodes_All(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/any.rb b/lib/arel/extensions/any.rb index 327a08fb..54375a06 100644 --- a/lib/arel/extensions/any.rb +++ b/lib/arel/extensions/any.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class Any < Arel::Nodes::Unary module Visitors class ToSql + sig { params(o: Arel::Nodes::Any, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Any(o, collector) collector << 'ANY(' visit o.expr, collector @@ -20,4 +22,4 @@ def visit_Arel_Nodes_Any(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/array.rb b/lib/arel/extensions/array.rb index 184e0b55..53823f88 100644 --- a/lib/arel/extensions/array.rb +++ b/lib/arel/extensions/array.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -6,6 +7,7 @@ module Nodes class Array < Arel::Nodes::Node attr_reader :items + sig { params(items: T::Array[T.any(Integer, Arel::Nodes::SqlLiteral)]).void } def initialize(items) super() @@ -16,6 +18,7 @@ def initialize(items) module Visitors class ToSql + sig { params(o: Arel::Nodes::Array, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Array(o, collector) collector << 'ARRAY[' inject_join(o.items, collector, ', ') @@ -26,4 +29,4 @@ def visit_Arel_Nodes_Array(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/array_subselect.rb b/lib/arel/extensions/array_subselect.rb index 0d227fc3..f593ec62 100644 --- a/lib/arel/extensions/array_subselect.rb +++ b/lib/arel/extensions/array_subselect.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class ArraySubselect < Arel::Nodes::Unary module Visitors class ToSql + sig { params(o: Arel::Nodes::ArraySubselect, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_ArraySubselect(o, collector) collector << 'ARRAY(' visit o.expr, collector @@ -20,4 +22,4 @@ def visit_Arel_Nodes_ArraySubselect(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/assignment.rb b/lib/arel/extensions/assignment.rb index 9914e9ff..605a0da6 100644 --- a/lib/arel/extensions/assignment.rb +++ b/lib/arel/extensions/assignment.rb @@ -1,8 +1,10 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName module Arel module Visitors class ToSql + sig { params(o: Arel::Nodes::Assignment, collector: T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)).returns(T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)) } def visit_Arel_Nodes_Assignment(o, collector) collector = visit o.left, collector collector << ' = ' @@ -19,4 +21,4 @@ def visit_Arel_Nodes_Assignment(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/at_time_zone.rb b/lib/arel/extensions/at_time_zone.rb index 16151d61..bab8e03e 100644 --- a/lib/arel/extensions/at_time_zone.rb +++ b/lib/arel/extensions/at_time_zone.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ module Nodes class AtTimeZone < Arel::Nodes::Unary attr_reader :timezone + sig { params(expr: T.any(Arel::Nodes::TypeCast, T::Array[Arel::Nodes::AtTimeZone], Arel::Nodes::Grouping), timezone: Arel::Nodes::Quoted).void } def initialize(expr, timezone) super(expr) @@ -17,6 +19,7 @@ def initialize(expr, timezone) module Visitors class ToSql + sig { params(o: Arel::Nodes::AtTimeZone, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_AtTimeZone(o, collector) visit o.expr, collector collector << ' AT TIME ZONE ' @@ -27,4 +30,4 @@ def visit_Arel_Nodes_AtTimeZone(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/between_symmetric.rb b/lib/arel/extensions/between_symmetric.rb index c9b61600..c7ba3ddf 100644 --- a/lib/arel/extensions/between_symmetric.rb +++ b/lib/arel/extensions/between_symmetric.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class BetweenSymmetric < Arel::Nodes::Between module Visitors class ToSql + sig { params(o: Arel::Nodes::BetweenSymmetric, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_BetweenSymmetric(o, collector) collector = visit o.left, collector collector << ' BETWEEN SYMMETRIC ' @@ -20,4 +22,4 @@ def visit_Arel_Nodes_BetweenSymmetric(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/bit_string.rb b/lib/arel/extensions/bit_string.rb index c558743a..b6334e1f 100644 --- a/lib/arel/extensions/bit_string.rb +++ b/lib/arel/extensions/bit_string.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -6,6 +7,7 @@ module Nodes class BitString < Arel::Nodes::Node attr_reader :str + sig { params(str: String).void } def initialize(str) super() @@ -16,6 +18,7 @@ def initialize(str) module Visitors class ToSql + sig { params(o: Arel::Nodes::BitString, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_BitString(o, collector) collector << "B'#{o.str[1..-1]}'" end @@ -24,4 +27,4 @@ def visit_Arel_Nodes_BitString(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/bitwise_xor.rb b/lib/arel/extensions/bitwise_xor.rb index 0edce5c9..3ee88e0a 100644 --- a/lib/arel/extensions/bitwise_xor.rb +++ b/lib/arel/extensions/bitwise_xor.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://github.com/mvgijssel/arel_toolkit/issues/45 class BitwiseXor < InfixOperation + sig { params(left: T.any(Integer, Arel::Nodes::TypeCast), right: T.any(Integer, Arel::Nodes::TypeCast)).void } def initialize(left, right) super('#', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/coalesce.rb b/lib/arel/extensions/coalesce.rb index cf31fe53..ab55fdde 100644 --- a/lib/arel/extensions/coalesce.rb +++ b/lib/arel/extensions/coalesce.rb @@ -1,9 +1,11 @@ +# typed: true module Arel module Nodes class Coalesce < Arel::Nodes::NamedFunction + sig { params(args: T::Array[T.any(Arel::Nodes::UnboundColumnReference, Arel::Nodes::SqlLiteral, Integer, Arel::Nodes::Quoted)]).void } def initialize(args) super 'COALESCE', args end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/conflict.rb b/lib/arel/extensions/conflict.rb index 25f326d5..9bc146f9 100644 --- a/lib/arel/extensions/conflict.rb +++ b/lib/arel/extensions/conflict.rb @@ -1,3 +1,4 @@ +# typed: false # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -15,6 +16,7 @@ class Conflict < Arel::Nodes::Node module Visitors class ToSql # rubocop:disable Metrics/AbcSize + sig { params(o: Arel::Nodes::Conflict, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Conflict(o, collector) collector << ' ON CONFLICT ' @@ -44,4 +46,4 @@ def visit_Arel_Nodes_Conflict(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/contained_by.rb b/lib/arel/extensions/contained_by.rb index eb638396..f1e0484c 100644 --- a/lib/arel/extensions/contained_by.rb +++ b/lib/arel/extensions/contained_by.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.1/functions-array.html class ContainedBy < InfixOperation + sig { params(left: T.any(Arel::Nodes::Array, Arel::Nodes::TypeCast), right: T.any(Arel::Nodes::Array, Arel::Nodes::TypeCast)).void } def initialize(left, right) super('<@', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/contained_within_equals.rb b/lib/arel/extensions/contained_within_equals.rb index 3c92c013..14636725 100644 --- a/lib/arel/extensions/contained_within_equals.rb +++ b/lib/arel/extensions/contained_within_equals.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.3/functions-net.html class ContainedWithinEquals < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: Arel::Nodes::TypeCast).void } def initialize(left, right) super(:'<<=', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/contains.rb b/lib/arel/extensions/contains.rb index 21dc7bbd..14797ae9 100644 --- a/lib/arel/extensions/contains.rb +++ b/lib/arel/extensions/contains.rb @@ -1,3 +1,4 @@ +# typed: false # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -5,6 +6,7 @@ module Arel if Gem.loaded_specs.key?('postgres_ext') module Visitors module ContainsPatch + sig { params(o: T.untyped, collector: T.untyped).returns(T.untyped) } def visit_Arel_Nodes_Contains(o, collector) if o.left.is_a?(Arel::Attribute) super @@ -20,6 +22,7 @@ def visit_Arel_Nodes_Contains(o, collector) module Nodes # https://www.postgresql.org/docs/9.1/functions-array.html class Contains < Arel::Nodes::InfixOperation + sig { params(left: T.any(Arel::Nodes::Array, Arel::Nodes::TypeCast), right: T.any(Arel::Nodes::Array, Arel::Nodes::TypeCast)).void } def initialize(left, right) super(:'@>', left, right) end @@ -29,4 +32,4 @@ def initialize(left, right) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/contains_equals.rb b/lib/arel/extensions/contains_equals.rb index d2547b6f..932c7753 100644 --- a/lib/arel/extensions/contains_equals.rb +++ b/lib/arel/extensions/contains_equals.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.3/functions-net.html class ContainsEquals < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: Arel::Nodes::TypeCast).void } def initialize(left, right) super(:'>>=', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/cross_join.rb b/lib/arel/extensions/cross_join.rb index 4878678f..581c98e8 100644 --- a/lib/arel/extensions/cross_join.rb +++ b/lib/arel/extensions/cross_join.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CrossJoin < Arel::Nodes::Join module Visitors class ToSql + sig { params(o: Arel::Nodes::CrossJoin, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CrossJoin(o, collector) collector << 'CROSS JOIN ' visit o.left, collector @@ -18,4 +20,4 @@ def visit_Arel_Nodes_CrossJoin(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/cube_root.rb b/lib/arel/extensions/cube_root.rb index 0b1504b5..db7609f8 100644 --- a/lib/arel/extensions/cube_root.rb +++ b/lib/arel/extensions/cube_root.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-math.html class CubeRoot < Arel::Nodes::UnaryOperation + sig { params(operand: Integer).void } def initialize(operand) super('||/', operand) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/current_catalog.rb b/lib/arel/extensions/current_catalog.rb index ec1b7081..35537027 100644 --- a/lib/arel/extensions/current_catalog.rb +++ b/lib/arel/extensions/current_catalog.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CurrentCatalog < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::CurrentCatalog, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentCatalog(_o, collector) collector << 'current_catalog' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_CurrentCatalog(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/current_date.rb b/lib/arel/extensions/current_date.rb index a1a3849e..3ba84175 100644 --- a/lib/arel/extensions/current_date.rb +++ b/lib/arel/extensions/current_date.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CurrentDate < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::CurrentDate, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentDate(_o, collector) collector << 'current_date' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_CurrentDate(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/current_of_expression.rb b/lib/arel/extensions/current_of_expression.rb index 6fc24991..0da8f6ba 100644 --- a/lib/arel/extensions/current_of_expression.rb +++ b/lib/arel/extensions/current_of_expression.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ module Nodes class CurrentOfExpression < Arel::Nodes::Node attr_accessor :cursor_name + sig { params(cursor_name: String).void } def initialize(cursor_name) super() @@ -17,6 +19,7 @@ def initialize(cursor_name) module Visitors class ToSql + sig { params(o: Arel::Nodes::CurrentOfExpression, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentOfExpression(o, collector) collector << 'CURRENT OF ' collector << o.cursor_name @@ -26,4 +29,4 @@ def visit_Arel_Nodes_CurrentOfExpression(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/current_role.rb b/lib/arel/extensions/current_role.rb index f9a3e204..166044ed 100644 --- a/lib/arel/extensions/current_role.rb +++ b/lib/arel/extensions/current_role.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CurrentRole < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::CurrentRole, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentRole(_o, collector) collector << 'current_role' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_CurrentRole(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/current_schema.rb b/lib/arel/extensions/current_schema.rb index 4abc2445..86cd8d1a 100644 --- a/lib/arel/extensions/current_schema.rb +++ b/lib/arel/extensions/current_schema.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CurrentSchema < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::CurrentSchema, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentSchema(_o, collector) collector << 'current_schema' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_CurrentSchema(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/current_time.rb b/lib/arel/extensions/current_time.rb index aad7c099..e15e4ef2 100644 --- a/lib/arel/extensions/current_time.rb +++ b/lib/arel/extensions/current_time.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CurrentTime < TimeWithPrecision module Visitors class ToSql + sig { params(o: Arel::Nodes::CurrentTime, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentTime(o, collector) collector << 'current_time' collector << "(#{o.precision.to_i})" if o.precision @@ -19,4 +21,4 @@ def visit_Arel_Nodes_CurrentTime(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/current_timestamp.rb b/lib/arel/extensions/current_timestamp.rb index c52b3c64..af968ad0 100644 --- a/lib/arel/extensions/current_timestamp.rb +++ b/lib/arel/extensions/current_timestamp.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CurrentTimestamp < TimeWithPrecision module Visitors class ToSql + sig { params(o: Arel::Nodes::CurrentTimestamp, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentTimestamp(o, collector) collector << 'current_timestamp' collector << "(#{o.precision.to_i})" if o.precision @@ -19,4 +21,4 @@ def visit_Arel_Nodes_CurrentTimestamp(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/current_user.rb b/lib/arel/extensions/current_user.rb index fefc2504..1c0f609b 100644 --- a/lib/arel/extensions/current_user.rb +++ b/lib/arel/extensions/current_user.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class CurrentUser < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::CurrentUser, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_CurrentUser(_o, collector) collector << 'current_user' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_CurrentUser(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/default_values.rb b/lib/arel/extensions/default_values.rb index 91e86068..0fa735e1 100644 --- a/lib/arel/extensions/default_values.rb +++ b/lib/arel/extensions/default_values.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class DefaultValues < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::DefaultValues, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_DefaultValues(_o, collector) collector << 'DEFAULT VALUES' end @@ -18,4 +20,4 @@ def visit_Arel_Nodes_DefaultValues(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/delete_manager.rb b/lib/arel/extensions/delete_manager.rb index 5da693f2..c689b61f 100644 --- a/lib/arel/extensions/delete_manager.rb +++ b/lib/arel/extensions/delete_manager.rb @@ -1,4 +1,6 @@ +# typed: true Arel::DeleteManager.class_eval do + sig { params(other: Arel::DeleteManager).returns(T::Boolean) } def ==(other) @ast == other.ast && @ctx == other.ctx end @@ -6,4 +8,4 @@ def ==(other) protected attr_reader :ctx -end +end \ No newline at end of file diff --git a/lib/arel/extensions/delete_statement.rb b/lib/arel/extensions/delete_statement.rb index d586cde6..f356cf1b 100644 --- a/lib/arel/extensions/delete_statement.rb +++ b/lib/arel/extensions/delete_statement.rb @@ -1,3 +1,4 @@ +# typed: false # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ module Nodes attr_accessor :returning alias_method :old_initialize, :initialize + sig { params(relation: T.untyped, wheres: T::Array).void } def initialize(relation = nil, wheres = []) old_initialize(relation, wheres) @@ -21,6 +23,7 @@ def initialize(relation = nil, wheres = []) module Visitors class ToSql # rubocop:disable Metrics/AbcSize + sig { params(o: Arel::Nodes::DeleteStatement, collector: T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)).returns(T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)) } def visit_Arel_Nodes_DeleteStatement(o, collector) if o.with collector = visit o.with, collector @@ -53,4 +56,4 @@ def visit_Arel_Nodes_DeleteStatement(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/distinct_from.rb b/lib/arel/extensions/distinct_from.rb index 8ff6a684..8a4f6e7e 100644 --- a/lib/arel/extensions/distinct_from.rb +++ b/lib/arel/extensions/distinct_from.rb @@ -1,9 +1,11 @@ +# typed: true module Arel module Nodes class DistinctFrom < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::UnboundColumnReference, right: Arel::Nodes::UnboundColumnReference).void } def initialize(left, right) super(:'IS DISTINCT FROM', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/equality.rb b/lib/arel/extensions/equality.rb index e6844bd7..1fc9aad2 100644 --- a/lib/arel/extensions/equality.rb +++ b/lib/arel/extensions/equality.rb @@ -1,9 +1,11 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName module Arel module Visitors class ToSql + sig { params(o: Arel::Nodes::Equality, collector: T.any(Arel::Collectors::Composite, Arel::Collectors::SQLString, Arel::Collectors::SubstituteBinds)).returns(T.any(Arel::Collectors::Composite, Arel::Collectors::SQLString, Arel::Collectors::SubstituteBinds)) } def visit_Arel_Nodes_Equality(o, collector) right = o.right collector = visit o.left, collector @@ -25,4 +27,4 @@ def visit_Arel_Nodes_Equality(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/except_all.rb b/lib/arel/extensions/except_all.rb index 5044389d..1cfb21c5 100644 --- a/lib/arel/extensions/except_all.rb +++ b/lib/arel/extensions/except_all.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class ExceptAll < Binary module Visitors class ToSql + sig { params(o: Arel::Nodes::ExceptAll, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_ExceptAll(o, collector) collector << '( ' infix_value(o, collector, ' EXCEPT ALL ') << ' )' @@ -18,4 +20,4 @@ def visit_Arel_Nodes_ExceptAll(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/exponentiation.rb b/lib/arel/extensions/exponentiation.rb index 70dfa760..749978f7 100644 --- a/lib/arel/extensions/exponentiation.rb +++ b/lib/arel/extensions/exponentiation.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.1/functions-array.html class Exponentiation < InfixOperation + sig { params(left: Arel::Nodes::SqlLiteral, right: Arel::Nodes::SqlLiteral).void } def initialize(left, right) super(:^, left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/extract_from.rb b/lib/arel/extensions/extract_from.rb index ab164061..46137e57 100644 --- a/lib/arel/extensions/extract_from.rb +++ b/lib/arel/extensions/extract_from.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ module Nodes class ExtractFrom < Arel::Nodes::Unary attr_reader :field + sig { params(expr: T.any(Arel::Nodes::TypeCast, Arel::Attributes::Attribute), field: Arel::Nodes::Quoted).void } def initialize(expr, field) super(expr) @@ -17,6 +19,7 @@ def initialize(expr, field) module Visitors class ToSql + sig { params(o: Arel::Nodes::ExtractFrom, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_ExtractFrom(o, collector) collector << 'extract(' visit o.field, collector @@ -29,4 +32,4 @@ def visit_Arel_Nodes_ExtractFrom(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/factorial.rb b/lib/arel/extensions/factorial.rb index 44e26ef2..a95e1060 100644 --- a/lib/arel/extensions/factorial.rb +++ b/lib/arel/extensions/factorial.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ module Nodes class Factorial < Arel::Nodes::Unary attr_accessor :prefix + sig { params(expr: T.any(Integer, Arel::Nodes::TypeCast), prefix: T::Boolean).void } def initialize(expr, prefix) super(expr) @prefix = prefix @@ -16,6 +18,7 @@ def initialize(expr, prefix) module Visitors class ToSql + sig { params(o: Arel::Nodes::Factorial, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Factorial(o, collector) if o.prefix collector << '!! ' @@ -30,4 +33,4 @@ def visit_Arel_Nodes_Factorial(o, collector) end # rubocop:enable Naming/UncommunicativeMethodParamName -# rubocop:enable Naming/MethodName +# rubocop:enable Naming/MethodName \ No newline at end of file diff --git a/lib/arel/extensions/function.rb b/lib/arel/extensions/function.rb index 487cc096..676f33bc 100644 --- a/lib/arel/extensions/function.rb +++ b/lib/arel/extensions/function.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/UncommunicativeMethodParamName module Arel @@ -10,6 +11,12 @@ module Nodes attr_accessor :within_group attr_accessor :variardic + sig { + params( + expr: T.any(T::Array, Arel::Nodes::SelectStatement), + aliaz: T.nilable(T.untyped) + ).void + } def initialize(expr, aliaz = nil) super() @expressions = expr @@ -25,6 +32,23 @@ class ToSql # rubocop:disable Metrics/PerceivedComplexity # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/AbcSize + sig { + params( + name: String, + o: T.any( + Arel::Nodes::NamedFunction, + Arel::Nodes::Sum, + Arel::Nodes::Coalesce, + Arel::Nodes::Avg, Arel::Nodes::Least, + Arel::Nodes::Greatest, + Arel::Nodes::Rank, Arel::Nodes::Count, + Arel::Nodes::GenerateSeries, + Arel::Nodes::Max, + Arel::Nodes::Min + ), + collector: Arel::Collectors::SQLString, + ).returns(Arel::Collectors::SQLString) + } def aggregate(name, o, collector) collector << "#{name}(" collector << 'DISTINCT ' if o.distinct diff --git a/lib/arel/extensions/generate_series.rb b/lib/arel/extensions/generate_series.rb index 3dc5eca3..e620e8c6 100644 --- a/lib/arel/extensions/generate_series.rb +++ b/lib/arel/extensions/generate_series.rb @@ -1,9 +1,11 @@ +# typed: true module Arel module Nodes class GenerateSeries < Arel::Nodes::NamedFunction + sig { params(args: T::Array[Integer]).void } def initialize(args) super 'GENERATE_SERIES', args end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/greatest.rb b/lib/arel/extensions/greatest.rb index 50b16fa1..1ca74b78 100644 --- a/lib/arel/extensions/greatest.rb +++ b/lib/arel/extensions/greatest.rb @@ -1,9 +1,11 @@ +# typed: true module Arel module Nodes class Greatest < Arel::Nodes::NamedFunction + sig { params(args: T::Array[T.any(Arel::Nodes::BindParam, Arel::Nodes::TypeCast, Arel::Nodes::SqlLiteral)]).void } def initialize(args) super 'GREATEST', args end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/indirection.rb b/lib/arel/extensions/indirection.rb index dbff8cc9..1abfc242 100644 --- a/lib/arel/extensions/indirection.rb +++ b/lib/arel/extensions/indirection.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ class Indirection < Arel::Nodes::Node attr_reader :arg attr_reader :indirection + sig { params(arg: Arel::Nodes::UnboundColumnReference, indirection: T::Array[Integer]).void } def initialize(arg, indirection) super() @@ -18,6 +20,7 @@ def initialize(arg, indirection) module Visitors class ToSql + sig { params(o: Arel::Nodes::Indirection, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Indirection(o, collector) visit(o.arg, collector) collector << '[' @@ -29,4 +32,4 @@ def visit_Arel_Nodes_Indirection(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/infer.rb b/lib/arel/extensions/infer.rb index b3818948..059523c2 100644 --- a/lib/arel/extensions/infer.rb +++ b/lib/arel/extensions/infer.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -12,6 +13,7 @@ class Infer < Arel::Nodes::Node module Visitors class ToSql + sig { params(o: Arel::Nodes::Infer, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Infer(o, collector) if o.name collector << 'ON CONSTRAINT ' @@ -32,4 +34,4 @@ def visit_Arel_Nodes_Infer(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/insert_manager.rb b/lib/arel/extensions/insert_manager.rb index 7d84a92a..4f103ed2 100644 --- a/lib/arel/extensions/insert_manager.rb +++ b/lib/arel/extensions/insert_manager.rb @@ -1,5 +1,7 @@ +# typed: true Arel::InsertManager.class_eval do + sig { params(other: Arel::InsertManager).returns(T::Boolean) } def ==(other) @ast == other.ast end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/insert_statement.rb b/lib/arel/extensions/insert_statement.rb index a35a6a0b..3430b960 100644 --- a/lib/arel/extensions/insert_statement.rb +++ b/lib/arel/extensions/insert_statement.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ module InsertStatementExtensions attr_accessor :override attr_accessor :returning + sig { void } def initialize super @@ -25,6 +27,7 @@ class ToSql # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/PerceivedComplexity + sig { params(o: Arel::Nodes::InsertStatement, collector: T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)).returns(T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)) } def visit_Arel_Nodes_InsertStatement(o, collector) if o.with collector = visit o.with, collector @@ -75,4 +78,4 @@ def visit_Arel_Nodes_InsertStatement(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/intersect_all.rb b/lib/arel/extensions/intersect_all.rb index 52f2ae3f..f547bfe2 100644 --- a/lib/arel/extensions/intersect_all.rb +++ b/lib/arel/extensions/intersect_all.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class IntersectAll < Binary module Visitors class ToSql + sig { params(o: Arel::Nodes::IntersectAll, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_IntersectAll(o, collector) collector << '( ' infix_value(o, collector, ' INTERSECT ALL ') << ' )' @@ -18,4 +20,4 @@ def visit_Arel_Nodes_IntersectAll(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/json_get_field.rb b/lib/arel/extensions/json_get_field.rb index 1a0b3dcf..e10292b6 100644 --- a/lib/arel/extensions/json_get_field.rb +++ b/lib/arel/extensions/json_get_field.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSON-OP-TABLE class JsonGetField < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: T.any(Integer, Arel::Nodes::Quoted)).void } def initialize(left, right) super(:'->>', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/json_get_object.rb b/lib/arel/extensions/json_get_object.rb index e0fecd28..69a5d993 100644 --- a/lib/arel/extensions/json_get_object.rb +++ b/lib/arel/extensions/json_get_object.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSON-OP-TABLE class JsonGetObject < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: T.any(Integer, Arel::Nodes::Quoted)).void } def initialize(left, right) super(:'->', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/json_path_get_field.rb b/lib/arel/extensions/json_path_get_field.rb index cbc83287..da78d45e 100644 --- a/lib/arel/extensions/json_path_get_field.rb +++ b/lib/arel/extensions/json_path_get_field.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSON-OP-TABLE class JsonPathGetField < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: Arel::Nodes::Quoted).void } def initialize(left, right) super(:'#>>', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/json_path_get_object.rb b/lib/arel/extensions/json_path_get_object.rb index 666c79b7..cda7f1af 100644 --- a/lib/arel/extensions/json_path_get_object.rb +++ b/lib/arel/extensions/json_path_get_object.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSON-OP-TABLE class JsonPathGetObject < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: Arel::Nodes::Quoted).void } def initialize(left, right) super(:'#>', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/jsonb_all_key_exists.rb b/lib/arel/extensions/jsonb_all_key_exists.rb index f8de4c4b..d3a617e2 100644 --- a/lib/arel/extensions/jsonb_all_key_exists.rb +++ b/lib/arel/extensions/jsonb_all_key_exists.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE class JsonbAllKeyExists < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: Arel::Nodes::Array).void } def initialize(left, right) super(:'?&', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/jsonb_any_key_exists.rb b/lib/arel/extensions/jsonb_any_key_exists.rb index fdd279db..9b9adb42 100644 --- a/lib/arel/extensions/jsonb_any_key_exists.rb +++ b/lib/arel/extensions/jsonb_any_key_exists.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE class JsonbAnyKeyExists < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: T.any(Arel::Nodes::Array, Arel::Nodes::TypeCast)).void } def initialize(left, right) super(:'?|', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/jsonb_key_exists.rb b/lib/arel/extensions/jsonb_key_exists.rb index 4869b5ee..efa4a9f2 100644 --- a/lib/arel/extensions/jsonb_key_exists.rb +++ b/lib/arel/extensions/jsonb_key_exists.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE class JsonbKeyExists < Arel::Nodes::InfixOperation + sig { params(left: Arel::Nodes::TypeCast, right: Arel::Nodes::Quoted).void } def initialize(left, right) super(:'?', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/lateral.rb b/lib/arel/extensions/lateral.rb index 123ea75a..4473f170 100644 --- a/lib/arel/extensions/lateral.rb +++ b/lib/arel/extensions/lateral.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -11,12 +12,14 @@ class Lateral < Arel::Nodes::Unary module Visitors class ToSql # https://github.com/mvgijssel/arel_toolkit/issues/46 + sig { params(o: Arel::Nodes::Lateral, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Lateral(o, collector) collector << 'LATERAL ' grouping_parentheses o, collector end # https://github.com/mvgijssel/arel_toolkit/issues/46 + sig { params(o: Arel::Nodes::Lateral, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def grouping_parentheses(o, collector) if o.expr.is_a? Nodes::SelectStatement collector << '(' @@ -31,4 +34,4 @@ def grouping_parentheses(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/least.rb b/lib/arel/extensions/least.rb index 82ab0798..18afb578 100644 --- a/lib/arel/extensions/least.rb +++ b/lib/arel/extensions/least.rb @@ -1,9 +1,11 @@ +# typed: true module Arel module Nodes class Least < Arel::Nodes::NamedFunction + sig { params(args: T::Array[T.any(Integer, Arel::Nodes::UnboundColumnReference, Arel::Nodes::Quoted)]).void } def initialize(args) super 'LEAST', args end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/local_time.rb b/lib/arel/extensions/local_time.rb index 2725530e..be5143f0 100644 --- a/lib/arel/extensions/local_time.rb +++ b/lib/arel/extensions/local_time.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class LocalTime < TimeWithPrecision module Visitors class ToSql + sig { params(o: Arel::Nodes::LocalTime, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_LocalTime(o, collector) collector << 'localtime' collector << "(#{o.precision.to_i})" if o.precision @@ -19,4 +21,4 @@ def visit_Arel_Nodes_LocalTime(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/local_timestamp.rb b/lib/arel/extensions/local_timestamp.rb index ad2eb520..fe7d6a00 100644 --- a/lib/arel/extensions/local_timestamp.rb +++ b/lib/arel/extensions/local_timestamp.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class LocalTimestamp < TimeWithPrecision module Visitors class ToSql + sig { params(o: Arel::Nodes::LocalTimestamp, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_LocalTimestamp(o, collector) collector << 'localtimestamp' collector << "(#{o.precision.to_i})" if o.precision @@ -19,4 +21,4 @@ def visit_Arel_Nodes_LocalTimestamp(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/modulo.rb b/lib/arel/extensions/modulo.rb index 40b7de53..f49b48eb 100644 --- a/lib/arel/extensions/modulo.rb +++ b/lib/arel/extensions/modulo.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-math.html class Modulo < Arel::Nodes::InfixOperation + sig { params(left: Integer, right: Integer).void } def initialize(left, right) super(:%, left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/named_argument.rb b/lib/arel/extensions/named_argument.rb index 4aac6a3c..c95339ad 100644 --- a/lib/arel/extensions/named_argument.rb +++ b/lib/arel/extensions/named_argument.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ class NamedArgument < Arel::Nodes::Node attr_reader :name attr_reader :value + sig { params(name: String, value: Integer).void } def initialize(name, value) @name = name @value = value @@ -16,6 +18,7 @@ def initialize(name, value) module Visitors class ToSql + sig { params(o: Arel::Nodes::NamedArgument, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NamedArgument(o, collector) collector << o.name collector << ' => ' @@ -26,4 +29,4 @@ def visit_Arel_Nodes_NamedArgument(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/named_function.rb b/lib/arel/extensions/named_function.rb index 1dda4621..0355132c 100644 --- a/lib/arel/extensions/named_function.rb +++ b/lib/arel/extensions/named_function.rb @@ -1,9 +1,11 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName module Arel module Visitors class ToSql + sig { params(o: T.any(Arel::Nodes::NamedFunction, Arel::Nodes::Coalesce, Arel::Nodes::Least, Arel::Nodes::Greatest, Arel::Nodes::Rank, Arel::Nodes::GenerateSeries), collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NamedFunction(o, collector) aggregate(o.name, o, collector) end @@ -12,4 +14,4 @@ def visit_Arel_Nodes_NamedFunction(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/natural_join.rb b/lib/arel/extensions/natural_join.rb index 729df072..09fd0d9b 100644 --- a/lib/arel/extensions/natural_join.rb +++ b/lib/arel/extensions/natural_join.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class NaturalJoin < Arel::Nodes::Join module Visitors class ToSql + sig { params(o: Arel::Nodes::NaturalJoin, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NaturalJoin(o, collector) collector << 'NATURAL JOIN ' visit o.left, collector @@ -18,4 +20,4 @@ def visit_Arel_Nodes_NaturalJoin(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/not_between.rb b/lib/arel/extensions/not_between.rb index eb789b4c..fa03f8f3 100644 --- a/lib/arel/extensions/not_between.rb +++ b/lib/arel/extensions/not_between.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class NotBetween < Arel::Nodes::Between module Visitors class ToSql + sig { params(o: Arel::Nodes::NotBetween, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NotBetween(o, collector) collector = visit o.left, collector collector << ' NOT BETWEEN ' @@ -19,4 +21,4 @@ def visit_Arel_Nodes_NotBetween(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/not_between_symmetric.rb b/lib/arel/extensions/not_between_symmetric.rb index 8a12d055..787dc82e 100644 --- a/lib/arel/extensions/not_between_symmetric.rb +++ b/lib/arel/extensions/not_between_symmetric.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class NotBetweenSymmetric < Arel::Nodes::BetweenSymmetric module Visitors class ToSql + sig { params(o: Arel::Nodes::NotBetweenSymmetric, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NotBetweenSymmetric(o, collector) collector = visit o.left, collector collector << ' NOT BETWEEN SYMMETRIC ' @@ -20,4 +22,4 @@ def visit_Arel_Nodes_NotBetweenSymmetric(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/not_distinct_from.rb b/lib/arel/extensions/not_distinct_from.rb index 1b482263..08fc9655 100644 --- a/lib/arel/extensions/not_distinct_from.rb +++ b/lib/arel/extensions/not_distinct_from.rb @@ -1,9 +1,11 @@ +# typed: true module Arel module Nodes class NotDistinctFrom < Arel::Nodes::InfixOperation + sig { params(left: Integer, right: Arel::Nodes::Quoted).void } def initialize(left, right) super(:'IS NOT DISTINCT FROM', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/not_equal.rb b/lib/arel/extensions/not_equal.rb index 383d027a..e85c0eff 100644 --- a/lib/arel/extensions/not_equal.rb +++ b/lib/arel/extensions/not_equal.rb @@ -1,9 +1,11 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName module Arel module Visitors class ToSql + sig { params(o: Arel::Nodes::NotEqual, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NotEqual(o, collector) right = o.right collector = visit o.left, collector @@ -25,4 +27,4 @@ def visit_Arel_Nodes_NotEqual(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/not_similar.rb b/lib/arel/extensions/not_similar.rb index 58a30fd4..1b71a053 100644 --- a/lib/arel/extensions/not_similar.rb +++ b/lib/arel/extensions/not_similar.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class NotSimilar < Arel::Nodes::Similar module Visitors class ToSql + sig { params(o: Arel::Nodes::NotSimilar, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NotSimilar(o, collector) visit o.left, collector collector << ' NOT SIMILAR TO ' @@ -26,4 +28,4 @@ def visit_Arel_Nodes_NotSimilar(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/null_if.rb b/lib/arel/extensions/null_if.rb index e89a616e..24866a5e 100644 --- a/lib/arel/extensions/null_if.rb +++ b/lib/arel/extensions/null_if.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class NullIf < Arel::Nodes::Binary module Visitors class ToSql + sig { params(o: Arel::Nodes::NullIf, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_NullIf(o, collector) collector << 'NULLIF(' visit o.left, collector @@ -21,4 +23,4 @@ def visit_Arel_Nodes_NullIf(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/ordering.rb b/lib/arel/extensions/ordering.rb index 2c4c51cd..5a4c00d8 100644 --- a/lib/arel/extensions/ordering.rb +++ b/lib/arel/extensions/ordering.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ module Nodes # Postgres: https://www.postgresql.org/docs/9.4/queries-order.html attr_accessor :nulls + sig { params(expr: T.any(Arel::Nodes::UnboundColumnReference, Integer, Arel::Nodes::Quoted), nulls: Integer).void } def initialize(expr, nulls = 0) super(expr) @@ -18,17 +20,20 @@ def initialize(expr, nulls = 0) module Visitors class ToSql alias old_visit_Arel_Nodes_Ascending visit_Arel_Nodes_Ascending + sig { params(o: Arel::Nodes::Ascending, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Ascending(o, collector) old_visit_Arel_Nodes_Ascending(o, collector) apply_ordering_nulls(o, collector) end alias old_visit_Arel_Nodes_Descending visit_Arel_Nodes_Descending + sig { params(o: Arel::Nodes::Descending, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Descending(o, collector) old_visit_Arel_Nodes_Descending(o, collector) apply_ordering_nulls(o, collector) end + sig { params(o: T.any(Arel::Nodes::Descending, Arel::Nodes::Ascending), collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def apply_ordering_nulls(o, collector) case o.nulls when 1 @@ -44,4 +49,4 @@ def apply_ordering_nulls(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/overlap.rb b/lib/arel/extensions/overlap.rb index a247755d..486d703b 100644 --- a/lib/arel/extensions/overlap.rb +++ b/lib/arel/extensions/overlap.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.1/functions-array.html class Overlap < Arel::Nodes::InfixOperation + sig { params(left: T.any(Arel::Nodes::Array, Arel::Nodes::NamedFunction, Arel::Nodes::TypeCast), right: T.any(Arel::Nodes::Array, Arel::Nodes::NamedFunction, Arel::Nodes::TypeCast)).void } def initialize(left, right) super(:'&&', left, right) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/overlaps.rb b/lib/arel/extensions/overlaps.rb index b8df8726..eaf62c2b 100644 --- a/lib/arel/extensions/overlaps.rb +++ b/lib/arel/extensions/overlaps.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class Overlaps < Arel::Nodes::Node attr_reader :start2 attr_reader :end2 + sig { params(start1: Arel::Nodes::TypeCast, end1: Arel::Nodes::TypeCast, start2: Arel::Nodes::TypeCast, end2: Arel::Nodes::TypeCast).void } def initialize(start1, end1, start2, end2) @start1 = start1 @end1 = end1 @@ -21,6 +23,7 @@ def initialize(start1, end1, start2, end2) module Visitors class ToSql + sig { params(o: Arel::Nodes::Overlaps, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Overlaps(o, collector) collector << '(' visit o.start1, collector @@ -37,4 +40,4 @@ def visit_Arel_Nodes_Overlaps(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/overlay.rb b/lib/arel/extensions/overlay.rb index 8e1cc232..5496fdea 100644 --- a/lib/arel/extensions/overlay.rb +++ b/lib/arel/extensions/overlay.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName # rubocop:disable Metrics/AbcSize @@ -11,6 +12,7 @@ class Overlay < Arel::Nodes::Node attr_reader :start attr_reader :length + sig { params(string: T.any(Arel::Nodes::Quoted, Arel::Nodes::TypeCast), substring: T.any(Arel::Nodes::Quoted, Arel::Nodes::TypeCast), start: Integer, length: Integer).void } def initialize(string, substring, start, length = nil) @string = string @substring = substring @@ -22,6 +24,7 @@ def initialize(string, substring, start, length = nil) module Visitors class ToSql + sig { params(o: Arel::Nodes::Overlay, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Overlay(o, collector) collector << 'overlay(' visit o.string, collector @@ -41,4 +44,4 @@ def visit_Arel_Nodes_Overlay(o, collector) # rubocop:enable Naming/MethodName # rubocop:enable Naming/UncommunicativeMethodParamName -# rubocop:enable Metrics/AbcSize +# rubocop:enable Metrics/AbcSize \ No newline at end of file diff --git a/lib/arel/extensions/position.rb b/lib/arel/extensions/position.rb index c2cbe143..408d9b7a 100644 --- a/lib/arel/extensions/position.rb +++ b/lib/arel/extensions/position.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -8,6 +9,7 @@ class Position < Arel::Nodes::Node attr_reader :substring attr_reader :string + sig { params(substring: T.any(Arel::Nodes::Quoted, Arel::Nodes::TypeCast), string: T.any(Arel::Nodes::Quoted, Arel::Nodes::TypeCast)).void } def initialize(substring, string) @substring = substring @string = string @@ -17,6 +19,7 @@ def initialize(substring, string) module Visitors class ToSql + sig { params(o: Arel::Nodes::Position, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Position(o, collector) collector << 'position(' visit o.substring, collector @@ -29,4 +32,4 @@ def visit_Arel_Nodes_Position(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/range_function.rb b/lib/arel/extensions/range_function.rb index 8fe0a422..587ae9b5 100644 --- a/lib/arel/extensions/range_function.rb +++ b/lib/arel/extensions/range_function.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class RangeFunction < Arel::Nodes::Unary module Visitors class ToSql + sig { params(o: Arel::Nodes::RangeFunction, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_RangeFunction(o, collector) collector << 'ROWS FROM (' visit o.expr, collector @@ -20,4 +22,4 @@ def visit_Arel_Nodes_RangeFunction(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/rank.rb b/lib/arel/extensions/rank.rb index 54fb29ba..71f70566 100644 --- a/lib/arel/extensions/rank.rb +++ b/lib/arel/extensions/rank.rb @@ -1,9 +1,11 @@ +# typed: true module Arel module Nodes class Rank < Arel::Nodes::NamedFunction + sig { params(args: T::Array[Arel::Nodes::UnboundColumnReference]).void } def initialize(args) super 'RANK', args end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/row.rb b/lib/arel/extensions/row.rb index 00894217..f64b8638 100644 --- a/lib/arel/extensions/row.rb +++ b/lib/arel/extensions/row.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ module Nodes class Row < Arel::Nodes::Unary attr_reader :row_format + sig { params(args: T::Array[Arel::Nodes::SetToDefault], row_format: Integer).void } def initialize(args, row_format) super(args) @@ -17,6 +19,7 @@ def initialize(args, row_format) module Visitors class ToSql + sig { params(o: Arel::Nodes::Row, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Row(o, collector) collector << 'ROW(' visit o.expr, collector @@ -27,4 +30,4 @@ def visit_Arel_Nodes_Row(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/select_manager.rb b/lib/arel/extensions/select_manager.rb index 211292c8..5cb10d56 100644 --- a/lib/arel/extensions/select_manager.rb +++ b/lib/arel/extensions/select_manager.rb @@ -1,4 +1,6 @@ +# typed: true Arel::SelectManager.class_eval do + sig { params(other: Arel::SelectManager).returns(T::Boolean) } def ==(other) @ast == other.ast && @ctx == other.ctx end @@ -6,4 +8,4 @@ def ==(other) protected attr_reader :ctx -end +end \ No newline at end of file diff --git a/lib/arel/extensions/select_statement.rb b/lib/arel/extensions/select_statement.rb index 71410d73..7f0c4237 100644 --- a/lib/arel/extensions/select_statement.rb +++ b/lib/arel/extensions/select_statement.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -14,6 +15,7 @@ module Nodes module Visitors class ToSql alias old_visit_Nodes_SelectStatement visit_Arel_Nodes_SelectStatement + sig { params(o: Arel::Nodes::SelectStatement, collector: T.any(Arel::Collectors::Composite, Arel::Collectors::SQLString, Arel::Collectors::SubstituteBinds)).returns(T.any(Arel::Collectors::Composite, Arel::Collectors::SQLString, Arel::Collectors::SubstituteBinds)) } def visit_Arel_Nodes_SelectStatement(o, collector) visit(o.union, collector) if o.union old_visit_Nodes_SelectStatement(o, collector) @@ -23,4 +25,4 @@ def visit_Arel_Nodes_SelectStatement(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/session_user.rb b/lib/arel/extensions/session_user.rb index a7da1915..5be6dad6 100644 --- a/lib/arel/extensions/session_user.rb +++ b/lib/arel/extensions/session_user.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class SessionUser < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::SessionUser, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_SessionUser(_o, collector) collector << 'session_user' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_SessionUser(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/set_to_default.rb b/lib/arel/extensions/set_to_default.rb index cb63ec73..2f3b042c 100644 --- a/lib/arel/extensions/set_to_default.rb +++ b/lib/arel/extensions/set_to_default.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class SetToDefault < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::SetToDefault, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_SetToDefault(_o, collector) collector << 'DEFAULT' end @@ -18,4 +20,4 @@ def visit_Arel_Nodes_SetToDefault(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/similar.rb b/lib/arel/extensions/similar.rb index 994a867a..b90953ca 100644 --- a/lib/arel/extensions/similar.rb +++ b/lib/arel/extensions/similar.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -5,6 +6,13 @@ module Arel module Nodes # Postgres: https://www.postgresql.org/docs/9/functions-matching.html class Similar < Arel::Nodes::Matches + sig do + params( + left: Arel::Nodes::Quoted, + right: Arel::Nodes::Quoted, + escape: T.nilable(Arel::Nodes::Quoted), + ).void + end def initialize(left, right, escape = nil) super(left, right, escape, false) end @@ -13,6 +21,7 @@ def initialize(left, right, escape = nil) module Visitors class ToSql + sig { params(o: Arel::Nodes::Similar, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Similar(o, collector) visit o.left, collector collector << ' SIMILAR TO ' diff --git a/lib/arel/extensions/square_root.rb b/lib/arel/extensions/square_root.rb index c462f899..74333b73 100644 --- a/lib/arel/extensions/square_root.rb +++ b/lib/arel/extensions/square_root.rb @@ -1,10 +1,12 @@ +# typed: true module Arel module Nodes # https://www.postgresql.org/docs/9.4/functions-math.html class SquareRoot < Arel::Nodes::UnaryOperation + sig { params(operand: Integer).void } def initialize(operand) super('|/', operand) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/substring.rb b/lib/arel/extensions/substring.rb index 475600dd..e87ba580 100644 --- a/lib/arel/extensions/substring.rb +++ b/lib/arel/extensions/substring.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class Substring < Arel::Nodes::Node attr_reader :pattern attr_reader :escape + sig { params(string: T.any(Arel::Nodes::Quoted, Arel::Nodes::TypeCast), pattern: T.any(Integer, Arel::Nodes::Quoted), escape: T.nilable(Integer, Arel::Nodes::Quoted)).void } def initialize(string, pattern, escape) @string = string @pattern = pattern @@ -19,6 +21,7 @@ def initialize(string, pattern, escape) module Visitors class ToSql + sig { params(o: Arel::Nodes::Substring, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Substring(o, collector) collector << 'substring(' visit o.string, collector @@ -35,4 +38,4 @@ def visit_Arel_Nodes_Substring(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/table.rb b/lib/arel/extensions/table.rb index 993bc6f3..a72d08ed 100644 --- a/lib/arel/extensions/table.rb +++ b/lib/arel/extensions/table.rb @@ -1,3 +1,4 @@ +# typed: false # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName # rubocop:disable Metrics/ParameterLists @@ -13,6 +14,7 @@ module Nodes attr_accessor :relpersistence alias_method :old_initialize, :initialize + sig { params(name: String, as: String, type_caster: ActiveRecord::TypeCaster::Map, only: T::Boolean, schema_name: String, relpersistence: String).void } def initialize( name, as: nil, @@ -33,6 +35,7 @@ def initialize( module Visitors class ToSql alias old_visit_Arel_Table visit_Arel_Table + sig { params(o: Arel::Table, collector: T.any(Arel::Collectors::Composite, Arel::Collectors::SQLString, Arel::Collectors::SubstituteBinds)).returns(T.any(Arel::Collectors::Composite, Arel::Collectors::SQLString, Arel::Collectors::SubstituteBinds)) } def visit_Arel_Table(o, collector) collector << 'ONLY ' if o.only @@ -46,4 +49,4 @@ def visit_Arel_Table(o, collector) # rubocop:enable Naming/MethodName # rubocop:enable Naming/UncommunicativeMethodParamName -# rubocop:enable Metrics/ParameterLists +# rubocop:enable Metrics/ParameterLists \ No newline at end of file diff --git a/lib/arel/extensions/time_with_precision.rb b/lib/arel/extensions/time_with_precision.rb index f9057cea..57793153 100644 --- a/lib/arel/extensions/time_with_precision.rb +++ b/lib/arel/extensions/time_with_precision.rb @@ -1,8 +1,10 @@ +# typed: true module Arel module Nodes class TimeWithPrecision < Arel::Nodes::Node attr_reader :precision + sig { params(precision: Integer).void } def initialize(precision: nil) super() @@ -10,4 +12,4 @@ def initialize(precision: nil) end end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/transaction.rb b/lib/arel/extensions/transaction.rb index b35bc8a5..8740b16a 100644 --- a/lib/arel/extensions/transaction.rb +++ b/lib/arel/extensions/transaction.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName # rubocop:disable Metrics/CyclomaticComplexity @@ -10,6 +11,7 @@ class Transaction < Arel::Nodes::Node attr_reader :type attr_reader :options + sig { params(type: Integer, options: T::Array[String]).void } def initialize(type, options) @type = type @options = options @@ -19,6 +21,7 @@ def initialize(type, options) module Visitors class ToSql + sig { params(o: Arel::Nodes::Transaction, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Transaction(o, collector) case o.type when 0 @@ -47,4 +50,4 @@ def visit_Arel_Nodes_Transaction(o, collector) # rubocop:enable Naming/MethodName # rubocop:enable Naming/UncommunicativeMethodParamName # rubocop:enable Metrics/CyclomaticComplexity -# rubocop:enable Metrics/AbcSize +# rubocop:enable Metrics/AbcSize \ No newline at end of file diff --git a/lib/arel/extensions/trim.rb b/lib/arel/extensions/trim.rb index aee14a3a..b24e782c 100644 --- a/lib/arel/extensions/trim.rb +++ b/lib/arel/extensions/trim.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class Trim < Arel::Nodes::Node attr_reader :substring attr_reader :string + sig { params(type: String, substring: T.nilable(Arel::Nodes::Quoted, Arel::Nodes::TypeCast), string: T.any(Arel::Nodes::Quoted, Arel::Nodes::TypeCast)).void } def initialize(type, substring, string) @type = type @substring = substring @@ -19,6 +21,7 @@ def initialize(type, substring, string) module Visitors class ToSql + sig { params(o: Arel::Nodes::Trim, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Trim(o, collector) collector << "trim(#{o.type} " if o.substring @@ -33,4 +36,4 @@ def visit_Arel_Nodes_Trim(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/type_cast.rb b/lib/arel/extensions/type_cast.rb index dc91168e..e8e9c863 100644 --- a/lib/arel/extensions/type_cast.rb +++ b/lib/arel/extensions/type_cast.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -8,11 +9,13 @@ class TypeCast < Arel::Nodes::Node attr_reader :arg attr_reader :type_name + sig { params(arg: T.any(Arel::Nodes::Array, Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral, Integer, Arel::Nodes::UnboundColumnReference, Arel::Attributes::Attribute, Arel::Nodes::Grouping), type_name: String).void } def initialize(arg, type_name) @arg = arg @type_name = type_name end + sig { params(other: Arel::Nodes::TypeCast).returns(T::Boolean) } def ==(other) arg == other.arg && type_name == other.type_name end @@ -21,6 +24,7 @@ def ==(other) module Visitors class ToSql + sig { params(o: Arel::Nodes::TypeCast, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_TypeCast(o, collector) visit o.arg, collector collector << '::' @@ -31,4 +35,4 @@ def visit_Arel_Nodes_TypeCast(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/unbound_column_reference.rb b/lib/arel/extensions/unbound_column_reference.rb index 6746aadf..2ddc82c2 100644 --- a/lib/arel/extensions/unbound_column_reference.rb +++ b/lib/arel/extensions/unbound_column_reference.rb @@ -1,5 +1,6 @@ +# typed: strong module Arel module Nodes class UnboundColumnReference < ::Arel::Nodes::SqlLiteral; end end -end +end \ No newline at end of file diff --git a/lib/arel/extensions/unknown.rb b/lib/arel/extensions/unknown.rb index abc5540e..24f8cc7d 100644 --- a/lib/arel/extensions/unknown.rb +++ b/lib/arel/extensions/unknown.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class Unknown < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::Unknown, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_Unknown(_o, collector) collector << 'UNKNOWN' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_Unknown(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/update_manager.rb b/lib/arel/extensions/update_manager.rb index 7969dc78..abfa865c 100644 --- a/lib/arel/extensions/update_manager.rb +++ b/lib/arel/extensions/update_manager.rb @@ -1,4 +1,6 @@ +# typed: true Arel::UpdateManager.class_eval do + sig { params(other: Arel::UpdateManager).returns(T::Boolean) } def ==(other) @ast == other.ast && @ctx == other.ctx end @@ -6,4 +8,4 @@ def ==(other) protected attr_reader :ctx -end +end \ No newline at end of file diff --git a/lib/arel/extensions/update_statement.rb b/lib/arel/extensions/update_statement.rb index f0d44659..0c609d4d 100644 --- a/lib/arel/extensions/update_statement.rb +++ b/lib/arel/extensions/update_statement.rb @@ -1,3 +1,4 @@ +# typed: false # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ module Nodes attr_accessor :returning alias_method :old_initialize, :initialize + sig { void } def initialize old_initialize @@ -24,6 +26,7 @@ class ToSql # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/PerceivedComplexity + sig { params(o: Arel::Nodes::UpdateStatement, collector: T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)).returns(T.any(Arel::Collectors::SQLString, Arel::Collectors::Composite)) } def visit_Arel_Nodes_UpdateStatement(o, collector) if o.with collector = visit o.with, collector @@ -68,4 +71,4 @@ def visit_Arel_Nodes_UpdateStatement(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/user.rb b/lib/arel/extensions/user.rb index 3ce8b6fb..0a4e5d66 100644 --- a/lib/arel/extensions/user.rb +++ b/lib/arel/extensions/user.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -9,6 +10,7 @@ class User < Arel::Nodes::Node module Visitors class ToSql + sig { params(_o: Arel::Nodes::User, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_User(_o, collector) collector << 'user' end @@ -17,4 +19,4 @@ def visit_Arel_Nodes_User(_o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/variable_set.rb b/lib/arel/extensions/variable_set.rb index 93d32a7b..645b4df0 100644 --- a/lib/arel/extensions/variable_set.rb +++ b/lib/arel/extensions/variable_set.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class VariableSet < Arel::Nodes::Node attr_reader :name attr_reader :local + sig { params(type: Integer, args: T::Array, name: String, local: T::Boolean).void } def initialize(type, args, name, local) @type = type @args = args @@ -21,6 +23,7 @@ def initialize(type, args, name, local) module Visitors class ToSql + sig { params(o: Arel::Nodes::VariableSet, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_VariableSet(o, collector) collector << 'SET ' collector << 'LOCAL ' if o.local @@ -43,4 +46,4 @@ def visit_Arel_Nodes_VariableSet(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/variable_show.rb b/lib/arel/extensions/variable_show.rb index 330704bc..cc365d51 100644 --- a/lib/arel/extensions/variable_show.rb +++ b/lib/arel/extensions/variable_show.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -7,6 +8,7 @@ module Nodes class VariableShow < Arel::Nodes::Node attr_reader :name + sig { params(name: String).void } def initialize(name) @name = name end @@ -15,6 +17,7 @@ def initialize(name) module Visitors class ToSql + sig { params(o: Arel::Nodes::VariableShow, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_VariableShow(o, collector) collector << 'SHOW ' collector << if o.name == 'timezone' @@ -28,4 +31,4 @@ def visit_Arel_Nodes_VariableShow(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/extensions/with_ordinality.rb b/lib/arel/extensions/with_ordinality.rb index 45444ec9..cc1e79eb 100644 --- a/lib/arel/extensions/with_ordinality.rb +++ b/lib/arel/extensions/with_ordinality.rb @@ -1,3 +1,4 @@ +# typed: true # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName @@ -10,6 +11,7 @@ class WithOrdinality < Arel::Nodes::Unary module Visitors class ToSql + sig { params(o: Arel::Nodes::WithOrdinality, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_WithOrdinality(o, collector) visit o.expr, collector collector << ' WITH ORDINALITY' @@ -19,4 +21,4 @@ def visit_Arel_Nodes_WithOrdinality(o, collector) end # rubocop:enable Naming/MethodName -# rubocop:enable Naming/UncommunicativeMethodParamName +# rubocop:enable Naming/UncommunicativeMethodParamName \ No newline at end of file diff --git a/lib/arel/middleware.rb b/lib/arel/middleware.rb index e5652b3f..3bda2367 100644 --- a/lib/arel/middleware.rb +++ b/lib/arel/middleware.rb @@ -1,3 +1,4 @@ +# typed: true require 'active_record' require_relative './middleware/railtie' require_relative './middleware/chain' @@ -6,18 +7,21 @@ module Arel module Middleware class << self + sig { returns(Arel::Middleware::Chain) } def current_chain Thread.current[:arel_toolkit_middleware_current_chain] ||= Arel::Middleware::Chain.new end + sig { params(new_chain: Arel::Middleware::Chain).returns(Arel::Middleware::Chain) } def current_chain=(new_chain) Thread.current[:arel_toolkit_middleware_current_chain] = new_chain end end end + sig { returns(Arel::Middleware::Chain) } def self.middleware Arel::Middleware.current_chain end -end +end \ No newline at end of file diff --git a/lib/arel/middleware/chain.rb b/lib/arel/middleware/chain.rb index c0e4ad94..671c0cad 100644 --- a/lib/arel/middleware/chain.rb +++ b/lib/arel/middleware/chain.rb @@ -1,11 +1,14 @@ +# typed: true module Arel module Middleware class Chain + sig { params(internal_middleware: T::Array[Class], internal_context: T::Hash).void } def initialize(internal_middleware = [], internal_context = {}) @internal_middleware = internal_middleware @internal_context = internal_context end + sig { params(sql: String, binds: T::Array).returns(String) } def execute(sql, binds = []) return sql if internal_middleware.length.zero? @@ -21,22 +24,27 @@ def execute(sql, binds = []) result.to_sql end + sig { returns(T::Array) } def current internal_middleware.dup end + sig { params(middleware: T::Array[Class], block: Proc).returns(T.any(T::Array[Class], ActiveRecord::Relation, T::Boolean, Post, String, Arel::Middleware::Chain)) } def apply(middleware, &block) continue_chain(middleware, internal_context, &block) end + sig { params(middleware: T::Array[Class], block: Proc).returns(T::Array[Class]) } def only(middleware, &block) continue_chain(middleware, internal_context, &block) end + sig { params(block: Proc).returns(T.any(T::Array, T::Boolean, ActiveRecord::Relation)) } def none(&block) continue_chain([], internal_context, &block) end + sig { params(without_middleware: Class, block: Proc).returns(ActiveRecord::Relation) } def except(without_middleware, &block) new_middleware = internal_middleware.reject do |middleware| middleware == without_middleware @@ -45,18 +53,35 @@ def except(without_middleware, &block) continue_chain(new_middleware, internal_context, &block) end + sig { params(new_middleware: Class, existing_middleware: Class, block: Proc).returns(T::Array[Class]) } def insert_before(new_middleware, existing_middleware, &block) index = internal_middleware.index(existing_middleware) updated_middleware = internal_middleware.insert(index, new_middleware) continue_chain(updated_middleware, internal_context, &block) end + sig { params(new_middleware: Class, existing_middleware: Class, block: Proc).returns(T::Array[Class]) } def insert_after(new_middleware, existing_middleware, &block) index = internal_middleware.index(existing_middleware) updated_middleware = internal_middleware.insert(index + 1, new_middleware) continue_chain(updated_middleware, internal_context, &block) end + sig do + params( + new_context: T::Hash[Symbol, Symbol], + block: Proc, + ).returns( + T.any( + T::Boolean, + T::Array[Class], + ActiveRecord::Relation, + String, + Arel::Middleware::Chain, + ActiveRecord::Model, + ) + ) + end def context(new_context = nil, &block) if new_context.nil? && !block.nil? raise 'You cannot do a block statement while calling context without arguments' @@ -74,11 +99,27 @@ def context(new_context = nil, &block) private + sig { params(middleware: T::Array[Class], context: T::Hash, block: Proc).returns(T.any(T::Array[Class], ActiveRecord::Relation, T::Boolean, Post, String, Arel::Middleware::Chain)) } def continue_chain(middleware, context, &block) new_chain = Arel::Middleware::Chain.new(middleware, context) maybe_execute_block(new_chain, &block) end + sig do + params( + new_chain: Arel::Middleware::Chain, + block: Proc, + ).returns( + T.any( + T::Array[Class], + ActiveRecord::Relation, + T::Boolean, + Post, + String, + Arel::Middleware::Chain, + ), + ) + end def maybe_execute_block(new_chain, &block) return new_chain if block.nil? @@ -86,9 +127,10 @@ def maybe_execute_block(new_chain, &block) Arel::Middleware.current_chain = new_chain yield block ensure - Arel::Middleware.current_chain = previous_chain + Arel::Middleware.current_chain = T.must(previous_chain) end + sig { returns(T.untyped) } def current_chain Arel::Middleware.current_chain end diff --git a/lib/arel/middleware/postgresql_adapter.rb b/lib/arel/middleware/postgresql_adapter.rb index bc5aa80e..cdcbeb85 100644 --- a/lib/arel/middleware/postgresql_adapter.rb +++ b/lib/arel/middleware/postgresql_adapter.rb @@ -1,26 +1,31 @@ +# typed: false module Arel module Middleware module PostgreSQLAdapter + sig { params(args: T::Array[T::Hash[Symbol, String]]).void } def initialize(*args) Arel.middleware.none do super(*args) end end + sig { params(sql: String, name: String).returns(PG::Result) } def execute(sql, name = nil) sql = Arel::Middleware.current_chain.execute(sql) super(sql, name) end + sig { params(sql: String, name: String, binds: T::Array[ActiveRecord::Relation::QueryAttribute]).returns(PG::Result) } def exec_no_cache(sql, name, binds) sql = Arel::Middleware.current_chain.execute(sql, binds) super(sql, name, binds) end + sig { params(sql: String, name: String, binds: T::Array[ActiveRecord::Relation::QueryAttribute]).returns(PG::Result) } def exec_cache(sql, name, binds) sql = Arel::Middleware.current_chain.execute(sql, binds) super(sql, name, binds) end end end -end +end \ No newline at end of file diff --git a/lib/arel/middleware/railtie.rb b/lib/arel/middleware/railtie.rb index 3dce2664..2f861337 100644 --- a/lib/arel/middleware/railtie.rb +++ b/lib/arel/middleware/railtie.rb @@ -1,6 +1,8 @@ +# typed: true module Arel module Middleware class Railtie + sig { returns(Class) } def self.insert_postgresql ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend( Arel::Middleware::PostgreSQLAdapter, @@ -8,4 +10,4 @@ def self.insert_postgresql end end end -end +end \ No newline at end of file diff --git a/lib/arel/sql_formatter.rb b/lib/arel/sql_formatter.rb index 02e7ae5f..02c33f53 100644 --- a/lib/arel/sql_formatter.rb +++ b/lib/arel/sql_formatter.rb @@ -1,6 +1,8 @@ +# typed: true module Arel module Nodes class Node + sig { params(engine: T.untyped).returns(T.untyped) } def to_formatted_sql(engine = Table.engine) collector = Arel::Collectors::SQLString.new Arel::SqlFormatter.new(engine.connection).accept self, collector @@ -10,6 +12,7 @@ def to_formatted_sql(engine = Table.engine) end class TreeManager + sig { params(engine: Class).returns(String) } def to_formatted_sql(engine = Table.engine) collector = Arel::Collectors::SQLString.new Arel::SqlFormatter.new(engine.connection).accept @ast, collector @@ -18,6 +21,7 @@ def to_formatted_sql(engine = Table.engine) end class SqlFormatter < Arel::Visitors::PostgreSQL + sig { params(object: Arel::Nodes::SelectStatement, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def accept(object, collector) super object, collector collector << "\n" @@ -28,6 +32,7 @@ def accept(object, collector) # rubocop:disable Naming/MethodName # rubocop:disable Naming/UncommunicativeMethodParamName # rubocop:disable Metrics/AbcSize + sig { params(o: Arel::Nodes::SelectCore, collector: Arel::Collectors::SQLString).returns(Arel::Collectors::SQLString) } def visit_Arel_Nodes_SelectCore(o, collector) collector << "SELECT\n" @@ -56,4 +61,4 @@ def visit_Arel_Nodes_SelectCore(o, collector) # rubocop:enable Naming/MethodName # rubocop:enable Naming/UncommunicativeMethodParamName end -end +end \ No newline at end of file diff --git a/lib/arel/sql_to_arel.rb b/lib/arel/sql_to_arel.rb index 7ca4a1b1..6b56de56 100644 --- a/lib/arel/sql_to_arel.rb +++ b/lib/arel/sql_to_arel.rb @@ -1,8 +1,15 @@ +# typed: true require 'arel/sql_to_arel/result' require 'arel/sql_to_arel/error' require 'arel/sql_to_arel/pg_query_visitor' module Arel + sig do + params( + sql: String, + binds: T::Array, + ).returns(Arel::SqlToArel::Result) + end def self.sql_to_arel(sql, binds: []) SqlToArel::PgQueryVisitor.new.accept(sql, binds) end diff --git a/lib/arel/sql_to_arel/error.rb b/lib/arel/sql_to_arel/error.rb index 35b4d16a..d97ab695 100644 --- a/lib/arel/sql_to_arel/error.rb +++ b/lib/arel/sql_to_arel/error.rb @@ -1,6 +1,7 @@ +# typed: strong module Arel module SqlToArel class Error < StandardError end end -end +end \ No newline at end of file diff --git a/lib/arel/sql_to_arel/pg_query_visitor.rb b/lib/arel/sql_to_arel/pg_query_visitor.rb index da886fe7..432e110f 100644 --- a/lib/arel/sql_to_arel/pg_query_visitor.rb +++ b/lib/arel/sql_to_arel/pg_query_visitor.rb @@ -1,3 +1,4 @@ +# typed: false # rubocop:disable Metrics/PerceivedComplexity # rubocop:disable Naming/MethodName # rubocop:disable Metrics/CyclomaticComplexity @@ -18,6 +19,7 @@ class PgQueryVisitor attr_reader :binds attr_reader :sql + sig { params(sql: String, binds: T::Array).returns(Arel::SqlToArel::Result) } def accept(sql, binds = []) tree = PgQuery.parse(sql).tree @@ -34,14 +36,17 @@ def accept(sql, binds = []) private + sig { params(elements: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]]]).returns(Arel::Nodes::Array) } def visit_A_ArrayExpr(elements:) Arel::Nodes::Array.new visit(elements) end + sig { params(val: T::Hash[String, T::Hash[String, Integer]]).returns(T.any(Integer, Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral, Arel::Nodes::BitString)) } def visit_A_Const(val:) visit(val, :const) end + sig { params(kind: Integer, lexpr: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], rexpr: T.nilable(T::Hash[String, T::Hash[String, Integer]], T::Array[T::Hash[String, T::Hash[String, Integer]]]), name: T.any(String, T::Array[T::Hash[String, T::Hash[String, String]]])).returns(T.any(Arel::Nodes::Equality, Arel::Nodes::Addition, Arel::Nodes::Subtraction, Arel::Nodes::Multiplication, Arel::Nodes::Division, Arel::Nodes::Modulo, Arel::Nodes::Exponentiation, Arel::Nodes::SquareRoot, Arel::Nodes::CubeRoot, Arel::Nodes::Factorial, Arel::Nodes::Absolute, Arel::Nodes::BitwiseAnd, Arel::Nodes::BitwiseOr, Arel::Nodes::BitwiseXor, Arel::Nodes::BitwiseNot, Arel::Nodes::BitwiseShiftLeft, Arel::Nodes::BitwiseShiftRight, Arel::Nodes::LessThan, Arel::Nodes::GreaterThan, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual, Arel::Nodes::NotEqual, Arel::Nodes::Contains, Arel::Nodes::ContainedBy, Arel::Nodes::Overlap, Arel::Nodes::Concat, Arel::Nodes::ContainedWithinEquals, Arel::Nodes::ContainsEquals, Arel::Nodes::JsonGetObject, Arel::Nodes::JsonGetField, Arel::Nodes::JsonPathGetObject, Arel::Nodes::JsonPathGetField, Arel::Nodes::JsonbKeyExists, Arel::Nodes::JsonbAnyKeyExists, Arel::Nodes::JsonbAllKeyExists, Arel::Nodes::Regexp, Arel::Nodes::NotRegexp, Arel::Nodes::InfixOperation, Arel::Nodes::UnaryOperation, Arel::Nodes::DistinctFrom, Arel::Nodes::NotDistinctFrom, Arel::Nodes::NullIf, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::DoesNotMatch, Arel::Nodes::Matches, Arel::Nodes::Similar, Arel::Nodes::NotSimilar, Arel::Nodes::Between, Arel::Nodes::NotBetween, Arel::Nodes::BetweenSymmetric, Arel::Nodes::NotBetweenSymmetric)) } def visit_A_Expr(kind:, lexpr: nil, rexpr: nil, name:) case kind when PgQuery::AEXPR_OP @@ -179,26 +184,32 @@ def visit_A_Expr(kind:, lexpr: nil, rexpr: nil, name:) end end + sig { params(context: Symbol, uidx: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]]).returns(Integer) } def visit_A_Indices(context, uidx:) visit uidx, context end + sig { params(arg: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], indirection: T::Array[T::Hash[String, T::Hash[String, T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]]]]]).returns(Arel::Nodes::Indirection) } def visit_A_Indirection(arg:, indirection:) Arel::Nodes::Indirection.new(visit(arg), visit(indirection, :operator)) end + sig { returns(Arel::Nodes::SqlLiteral) } def visit_A_Star Arel.star end + sig { params(aliasname: String).returns(String) } def visit_Alias(aliasname:) aliasname end + sig { params(str: String).returns(Arel::Nodes::BitString) } def visit_BitString(str:) Arel::Nodes::BitString.new(str) end + sig { params(context: T::Boolean, args: T::Array[T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]]], boolop: Integer).returns(T.any(Arel::Nodes::And, Arel::Nodes::Grouping, Arel::Nodes::Or)) } def visit_BoolExpr(context = false, args:, boolop:) args = visit(args, context || true) @@ -223,6 +234,7 @@ def visit_BoolExpr(context = false, args:, boolop:) end end + sig { params(arg: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]], booltesttype: Integer).returns(T.any(Arel::Nodes::Equality, Arel::Nodes::NotEqual)) } def visit_BooleanTest(arg:, booltesttype:) arg = visit(arg) @@ -250,6 +262,7 @@ def visit_BooleanTest(arg:, booltesttype:) end end + sig { params(arg: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], args: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]], Integer)]]], defresult: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]])]]).returns(Arel::Nodes::Case) } def visit_CaseExpr(arg: nil, args:, defresult: nil) Arel::Nodes::Case.new.tap do |kees| kees.case = visit(arg) if arg @@ -264,6 +277,7 @@ def visit_CaseExpr(arg: nil, args:, defresult: nil) end end + sig { params(expr: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], result: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]]).returns(Arel::Nodes::When) } def visit_CaseWhen(expr:, result:) expr = visit(expr) result = visit(result) @@ -271,12 +285,14 @@ def visit_CaseWhen(expr:, result:) Arel::Nodes::When.new(expr, result) end + sig { params(args: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]]]).returns(Arel::Nodes::Coalesce) } def visit_CoalesceExpr(args:) args = visit(args) Arel::Nodes::Coalesce.new args end + sig { params(fields: T::Array[T::Hash[String, T::Hash[String, String]]]).returns(T.any(Arel::Nodes::UnboundColumnReference, Arel::Attributes::Attribute)) } def visit_ColumnRef(fields:) visited_fields = visit(fields) @@ -292,16 +308,19 @@ def visit_ColumnRef(fields:) end end + sig { params(ctename: String, ctequery: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]]).returns(Arel::Nodes::As) } def visit_CommonTableExpr(ctename:, ctequery:) cte_table = Arel::Table.new(ctename) cte_definition = visit(ctequery) Arel::Nodes::As.new(cte_table, Arel::Nodes::Grouping.new(cte_definition)) end + sig { params(cursor_name: String).returns(Arel::Nodes::CurrentOfExpression) } def visit_CurrentOfExpr(cursor_name:) Arel::Nodes::CurrentOfExpression.new(cursor_name) end + sig { params(defname: String, arg: T::Hash[String, T::Hash[String, String]], defaction: Integer).returns(String) } def visit_DefElem(defname:, arg:, defaction:) case defname when 'savepoint_name' @@ -311,6 +330,7 @@ def visit_DefElem(defname:, arg:, defaction:) end end + sig { params(relation: T::Hash[String, T::Hash[String, T.any(String, T::Boolean, Integer)]], using_clause: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Boolean, Integer)]]], where_clause: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, Integer]])]], returning_list: T::Array, with_clause: T::Hash[String, T::Hash[String, T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]], Integer)]]]]]).returns(Arel::DeleteManager) } def visit_DeleteStmt( relation:, using_clause: nil, @@ -330,11 +350,13 @@ def visit_DeleteStmt( delete_manager end + sig { params(str: String).returns(Arel::Nodes::SqlLiteral) } def visit_Float(str:) Arel::Nodes::SqlLiteral.new str end # https://github.com/postgres/postgres/blob/REL_10_1/src/include/nodes/parsenodes.h + sig { params(funcname: T::Array[T::Hash[String, T::Hash[String, String]]], args: T::Array[T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]]], agg_order: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], Integer)]]], agg_filter: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]])]], agg_within_group: T::Boolean, agg_star: T.untyped, agg_distinct: T::Boolean, func_variadic: T::Boolean, over: T::Hash[String, T::Hash[String, Integer]]).returns(T.any(Arel::Nodes::NamedFunction, Arel::Nodes::Sum, T::Array[Arel::Nodes::Trim], Arel::Nodes::Over, Arel::Nodes::Avg, Arel::Nodes::Rank, Arel::Nodes::Count, Arel::Nodes::GenerateSeries, Arel::Nodes::Max, Arel::Nodes::Min)) } def visit_FuncCall( funcname:, args: nil, @@ -443,6 +465,7 @@ def visit_FuncCall( end end + sig { params(conname: String, index_elems: T::Array[T::Hash[String, T::Hash[String, T.any(String, Integer)]]]).returns(Arel::Nodes::Infer) } def visit_InferClause(conname: nil, index_elems: nil) infer = Arel::Nodes::Infer.new infer.name = Arel.sql(conname) if conname @@ -450,6 +473,7 @@ def visit_InferClause(conname: nil, index_elems: nil) infer end + sig { params(name: String, ordering: Integer, nulls_ordering: Integer).returns(Arel::Nodes::SqlLiteral) } def visit_IndexElem(name:, ordering:, nulls_ordering:) boom "Unknown ordering `#{ordering}`" unless ordering.zero? boom "Unknown nulls ordering `#{ordering}`" unless nulls_ordering.zero? @@ -457,6 +481,7 @@ def visit_IndexElem(name:, ordering:, nulls_ordering:) Arel.sql visit_String(str: name) end + sig { params(relation: T::Hash[String, T::Hash[String, T.any(String, T::Boolean, Integer)]], cols: T::Array[T::Hash[String, T::Hash[String, T.any(String, Integer)]]], select_stmt: T::Hash[String, T::Hash[String, T.any(T::Array[T::Array[T::Hash[String, T::Hash[String, Integer]]]], Integer)]], on_conflict_clause: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(Integer, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]])]], Integer)]]], T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]])]])]], with_clause: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Boolean, Integer)]]], Integer)]], Integer)]]], T::Boolean)]], returning_list: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], Integer)]]], override: Integer).returns(Arel::InsertManager) } def visit_InsertStmt( relation:, cols: [], @@ -490,10 +515,12 @@ def visit_InsertStmt( insert_manager end + sig { params(ival: Integer).returns(Integer) } def visit_Integer(ival:) ival end + sig { params(jointype: Integer, is_natural: T::Boolean, larg: T::Hash[String, T::Hash[String, T::Hash[String, T::Hash[String, String]]]], rarg: T::Hash[String, T::Hash[String, T.any(T::Boolean, T::Hash[String, T::Hash[String, String]])]], quals: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], Integer)]]).returns(T::Array[T.any(Arel::Nodes::TableAlias, Arel::Nodes::InnerJoin)]) } def visit_JoinExpr(jointype:, is_natural: nil, larg:, rarg:, quals: nil) join_class = case jointype when 0 @@ -526,6 +553,7 @@ def visit_JoinExpr(jointype:, is_natural: nil, larg:, rarg:, quals: nil) end end + sig { params(strength: Integer, wait_policy: Integer).returns(Arel::Nodes::Lock) } def visit_LockingClause(strength:, wait_policy:) strength_clause = { 1 => 'FOR KEY SHARE', @@ -542,6 +570,7 @@ def visit_LockingClause(strength:, wait_policy:) Arel::Nodes::Lock.new Arel.sql("#{strength_clause}#{wait_policy_clause}") end + sig { params(op: Integer, args: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash], Integer)]]]).returns(T.any(Arel::Nodes::Least, Arel::Nodes::Greatest)) } def visit_MinMaxExpr(op:, args:) case op when 0 @@ -553,6 +582,7 @@ def visit_MinMaxExpr(op:, args:) end end + sig { params(arg: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], name: String, argnumber: Integer).returns(Arel::Nodes::NamedArgument) } def visit_NamedArgExpr(arg:, name:, argnumber:) arg = visit(arg) boom '' unless argnumber == -1 @@ -560,10 +590,12 @@ def visit_NamedArgExpr(arg:, name:, argnumber:) Arel::Nodes::NamedArgument.new(name, arg) end + sig { params(_: T::Hash).returns(Arel::Nodes::SqlLiteral) } def visit_Null(**_) Arel.sql 'NULL' end + sig { params(arg: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]], nulltesttype: Integer).returns(T.any(Arel::Nodes::Equality, Arel::Nodes::NotEqual)) } def visit_NullTest(arg:, nulltesttype:) arg = visit(arg) @@ -575,6 +607,7 @@ def visit_NullTest(arg:, nulltesttype:) end end + sig { params(action: Integer, infer: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, Integer)]]], Integer)]], target_list: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(Integer, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]])]], Integer)]]], where_clause: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]])]]).returns(Arel::Nodes::Conflict) } def visit_OnConflictClause(action:, infer: nil, target_list: nil, where_clause: nil) conflict = Arel::Nodes::Conflict.new conflict.action = action @@ -584,12 +617,14 @@ def visit_OnConflictClause(action:, infer: nil, target_list: nil, where_clause: conflict end + sig { params(number: Integer).returns(Arel::Nodes::BindParam) } def visit_ParamRef(number:) value = (binds[number - 1] unless binds.empty?) Arel::Nodes::BindParam.new(value) end + sig { params(is_rowsfrom: T::Boolean, functions: T::Array[T::Array[T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]]]], lateral: T::Boolean, ordinality: T::Boolean).returns(Arel::Nodes::WithOrdinality) } def visit_RangeFunction(is_rowsfrom:, functions:, lateral: false, ordinality: false) boom 'https://github.com/mvgijssel/arel_toolkit/issues/36' unless is_rowsfrom == true @@ -605,6 +640,7 @@ def visit_RangeFunction(is_rowsfrom:, functions:, lateral: false, ordinality: fa ordinality ? Arel::Nodes::WithOrdinality.new(node) : node end + sig { params(aliaz: T::Hash[String, T::Hash[String, String]], subquery: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]], lateral: T::Boolean).returns(T.any(Arel::Nodes::TableAlias, Arel::Nodes::Lateral)) } def visit_RangeSubselect(aliaz:, subquery:, lateral: false) aliaz = visit(aliaz) subquery = visit(subquery) @@ -612,6 +648,7 @@ def visit_RangeSubselect(aliaz:, subquery:, lateral: false) lateral ? Arel::Nodes::Lateral.new(node) : node end + sig { params(aliaz: T::Hash[String, T::Hash[String, String]], relname: String, inh: T::Boolean, relpersistence: String, schemaname: String).returns(Arel::Table) } def visit_RangeVar(aliaz: nil, relname:, inh: false, relpersistence:, schemaname: nil) Arel::Table.new( relname, @@ -622,10 +659,12 @@ def visit_RangeVar(aliaz: nil, relname:, inh: false, relpersistence:, schemaname ) end + sig { params(context: Symbol, args: T::Hash[Symbol, T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, String]], Integer)]]])]]]).returns(T.any(Arel::SelectManager, Arel::InsertManager, Arel::UpdateManager, Arel::DeleteManager, Arel::Nodes::Transaction, Arel::Nodes::VariableShow, Arel::Nodes::VariableSet)) } def visit_RawStmt(context, **args) visit(args.fetch(:stmt), context) end + sig { params(context: Symbol, val: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], name: String).returns(T.any(Arel::Nodes::NamedFunction, Integer, Arel::Nodes::Grouping, Arel::Nodes::Sum, Arel::Nodes::Addition, Arel::Nodes::Subtraction, Arel::Nodes::Division, Arel::Nodes::Modulo, Arel::Nodes::Exponentiation, Arel::Nodes::SquareRoot, Arel::Nodes::CubeRoot, Arel::Nodes::Factorial, Arel::Nodes::Absolute, Arel::Nodes::BitwiseAnd, Arel::Nodes::BitwiseOr, Arel::Nodes::BitwiseXor, Arel::Nodes::BitwiseNot, Arel::Nodes::BitwiseShiftLeft, Arel::Nodes::BitwiseShiftRight, Arel::Nodes::LessThan, Arel::Nodes::GreaterThan, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::Contains, Arel::Nodes::ContainedBy, Arel::Nodes::Overlap, Arel::Nodes::Concat, Arel::Nodes::ContainedWithinEquals, Arel::Nodes::ContainsEquals, Arel::Nodes::JsonGetObject, Arel::Nodes::JsonGetField, Arel::Nodes::JsonPathGetObject, Arel::Nodes::JsonPathGetField, Arel::Nodes::JsonbKeyExists, Arel::Nodes::JsonbAnyKeyExists, Arel::Nodes::JsonbAllKeyExists, Arel::Nodes::Regexp, Arel::Nodes::NotRegexp, Arel::Nodes::InfixOperation, Arel::Attributes::Attribute, Arel::Nodes::Multiplication, Arel::Nodes::UnaryOperation, Arel::Nodes::TypeCast, String, Arel::Nodes::Assignment, Arel::Nodes::CurrentDate, Arel::Nodes::CurrentTime, Arel::Nodes::CurrentTimestamp, T::Array[Arel::Nodes::Trim], Arel::Nodes::LocalTime, Arel::Nodes::LocalTimestamp, Arel::Nodes::SqlLiteral, Arel::Nodes::Over, Arel::Nodes::Row, Arel::Nodes::Quoted, Arel::Nodes::UnboundColumnReference, Arel::Nodes::BindParam, Arel::Nodes::Case, Arel::Nodes::Indirection, Arel::Nodes::Exists, Arel::Nodes::Avg, Arel::Nodes::In, Arel::Nodes::ArraySubselect, Arel::Nodes::Coalesce, Arel::Nodes::DistinctFrom, Arel::Nodes::NotDistinctFrom, Arel::Nodes::NullIf, Arel::Nodes::NotIn, Arel::Nodes::DoesNotMatch, Arel::Nodes::Matches, Arel::Nodes::Similar, Arel::Nodes::NotSimilar, Arel::Nodes::Between, Arel::Nodes::NotBetween, Arel::Nodes::BetweenSymmetric, Arel::Nodes::NotBetweenSymmetric, Arel::Nodes::As, Arel::Nodes::Array, Arel::Nodes::Least, Arel::Nodes::Greatest, Arel::Nodes::And, Arel::Nodes::Rank, Arel::Nodes::Count, Arel::Nodes::GenerateSeries, Arel::Nodes::Max, Arel::Nodes::Min, Arel::Nodes::CurrentRole, Arel::Nodes::CurrentUser, Arel::Nodes::SessionUser, Arel::Nodes::User, Arel::Nodes::CurrentCatalog, Arel::Nodes::CurrentSchema, Arel::Nodes::BitString)) } def visit_ResTarget(context, val: nil, name: nil) case context when :select @@ -649,10 +688,12 @@ def visit_ResTarget(context, val: nil, name: nil) end end + sig { params(args: T::Array[T::Hash[String, T::Hash[String, Integer]]], row_format: Integer).returns(Arel::Nodes::Row) } def visit_RowExpr(args:, row_format:) Arel::Nodes::Row.new(visit(args), row_format) end + sig { params(context: Symbol, from_clause: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Boolean, Integer)]]], limit_count: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], target_list: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], Integer)]]], sort_clause: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]], Integer)]]], where_clause: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, Integer]])]], limit_offset: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], distinct_clause: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]]], group_clause: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]]], having_clause: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]])]], with_clause: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]], Integer)]]], T::Boolean, Integer)]], locking_clause: T::Array[T::Hash[String, T::Hash[String, Integer]]], op: Integer, window_clause: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], Integer)]]], Integer)]]], values_lists: T::Array[T::Array[T::Hash[String, T::Hash[String, Integer]]]], all: T::Boolean, larg: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]], Integer)]]], Integer)]], rarg: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], Integer)]], Integer)]]], Integer)]]).returns(T.any(Arel::SelectManager, Arel::Nodes::SelectStatement)) } def visit_SelectStmt( context = nil, from_clause: nil, @@ -778,10 +819,12 @@ def visit_SelectStmt( end end + sig { params(_args: T::Hash).returns(Arel::Nodes::SetToDefault) } def visit_SetToDefault(_args) Arel::Nodes::SetToDefault.new end + sig { params(node: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], sortby_dir: Integer, sortby_nulls: Integer).returns(T.any(Arel::Nodes::Descending, Arel::Nodes::Ascending, Arel::Nodes::UnboundColumnReference)) } def visit_SortBy(node:, sortby_dir:, sortby_nulls:) result = visit(node) case sortby_dir @@ -794,6 +837,7 @@ def visit_SortBy(node:, sortby_dir:, sortby_nulls:) end end + sig { params(op: Integer, typmod: Integer).returns(T.any(Arel::Nodes::CurrentTimestamp, Arel::Nodes::CurrentDate, Arel::Nodes::CurrentTime, Arel::Nodes::LocalTime, Arel::Nodes::LocalTimestamp, Arel::Nodes::CurrentRole, Arel::Nodes::CurrentUser, Arel::Nodes::SessionUser, Arel::Nodes::User, Arel::Nodes::CurrentCatalog, Arel::Nodes::CurrentSchema)) } def visit_SQLValueFunction(op:, typmod:) [ -> { Arel::Nodes::CurrentDate.new }, @@ -814,6 +858,7 @@ def visit_SQLValueFunction(op:, typmod:) ][op].call end + sig { params(context: Symbol, str: String).returns(T.any(String, Arel::Nodes::Quoted)) } def visit_String(context = nil, str:) case context when :operator @@ -825,6 +870,7 @@ def visit_String(context = nil, str:) end end + sig { params(subselect: T.any(T::Array, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]]), sub_link_type: Integer, testexpr: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], oper_name: T::Array[T::Hash[String, T::Hash[String, String]]]).returns(T.any(Arel::Nodes::Grouping, Arel::Nodes::LessThanOrEqual, Arel::Nodes::Exists, Arel::Nodes::GreaterThan, Arel::Nodes::Equality, Arel::Nodes::In, Arel::Nodes::ArraySubselect)) } def visit_SubLink(subselect:, sub_link_type:, testexpr: nil, oper_name: nil) subselect = visit(subselect) testexpr = visit(testexpr) if testexpr @@ -840,6 +886,7 @@ def visit_SubLink(subselect:, sub_link_type:, testexpr: nil, oper_name: nil) generate_sublink(sub_link_type, subselect, testexpr, operator) end + sig { params(kind: Integer, options: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, String]], Integer)]]]).returns(Arel::Nodes::Transaction) } def visit_TransactionStmt(kind:, options: nil) Arel::Nodes::Transaction.new( kind, @@ -847,6 +894,7 @@ def visit_TransactionStmt(kind:, options: nil) ) end + sig { params(arg: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, String]], Integer)]], type_name: T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]]).returns(Arel::Nodes::TypeCast) } def visit_TypeCast(arg:, type_name:) arg = visit(arg) type_name = visit(type_name) @@ -854,6 +902,7 @@ def visit_TypeCast(arg:, type_name:) Arel::Nodes::TypeCast.new(maybe_add_grouping(arg), type_name) end + sig { params(names: T::Array[T::Hash[String, T::Hash[String, String]]], typemod: Integer, array_bounds: T::Array).returns(String) } def visit_TypeName(names:, typemod:, array_bounds: []) array_bounds = visit(array_bounds) @@ -887,6 +936,7 @@ def visit_TypeName(names:, typemod:, array_bounds: []) type_name end + sig { params(relation: T::Hash[String, T::Hash[String, T.any(String, T::Boolean, Integer)]], target_list: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, Integer]], Integer)]]], where_clause: T::Hash[String, T::Hash[String, T.any(Integer, T::Array[T::Hash[String, T::Hash[String, String]]], T::Hash[String, T::Hash[String, Integer]])]], from_clause: T::Array, returning_list: T::Array, with_clause: T::Hash[String, T::Hash[String, T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]], Integer)]]]]]).returns(Arel::UpdateManager) } def visit_UpdateStmt( relation:, target_list:, @@ -909,6 +959,7 @@ def visit_UpdateStmt( update_manager end + sig { params(kind: Integer, name: String, args: T::Array, is_local: T::Boolean).returns(Arel::Nodes::VariableSet) } def visit_VariableSetStmt(kind:, name:, args: [], is_local: false) Arel::Nodes::VariableSet.new( kind, @@ -918,10 +969,12 @@ def visit_VariableSetStmt(kind:, name:, args: [], is_local: false) ) end + sig { params(name: String).returns(Arel::Nodes::VariableShow) } def visit_VariableShowStmt(name:) Arel::Nodes::VariableShow.new(name) end + sig { params(partition_clause: T::Array[T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]]], order_clause: T::Array[T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, String]]], Integer)]], Integer)]]], frame_options: Integer, name: String, start_offset: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], end_offset: T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]]).returns(T.any(Arel::Nodes::Window, Arel::Nodes::NamedWindow)) } def visit_WindowDef( partition_clause: [], order_clause: [], @@ -946,6 +999,7 @@ def visit_WindowDef( end end + sig { params(ctes: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, T.any(T::Hash[String, T::Hash[String, Integer]], Integer)]], Integer)]]], Integer)]], Integer)]]], recursive: T::Boolean).returns(T.any(Arel::Nodes::With, Arel::Nodes::WithRecursive)) } def visit_WithClause(ctes:, recursive: false) if recursive Arel::Nodes::WithRecursive.new visit(ctes) @@ -954,6 +1008,7 @@ def visit_WithClause(ctes:, recursive: false) end end + sig { params(left: T.nilable(Arel::Nodes::UnboundColumnReference, Integer, Arel::Nodes::Subtraction, Arel::Nodes::SqlLiteral, Arel::Nodes::Array, Arel::Nodes::TypeCast, Arel::Nodes::Quoted, Arel::Nodes::NamedFunction, Arel::Nodes::Concat, Arel::Attributes::Attribute), right: T.nilable(Arel::Nodes::Quoted, Integer, Arel::Nodes::Addition, Arel::Nodes::Multiplication, Arel::Nodes::SqlLiteral, Arel::Nodes::Array, Arel::Nodes::TypeCast, Arel::Nodes::NamedFunction, Arel::Nodes::Overlap, Arel::Nodes::BindParam, Arel::Nodes::Any, Arel::Nodes::All, Arel::Nodes::Grouping, Arel::Nodes::UnboundColumnReference), operator: String).returns(T.any(Arel::Nodes::Equality, Arel::Nodes::Addition, Arel::Nodes::Subtraction, Arel::Nodes::Multiplication, Arel::Nodes::Division, Arel::Nodes::Modulo, Arel::Nodes::Exponentiation, Arel::Nodes::SquareRoot, Arel::Nodes::CubeRoot, Arel::Nodes::Factorial, Arel::Nodes::Absolute, Arel::Nodes::BitwiseAnd, Arel::Nodes::BitwiseOr, Arel::Nodes::BitwiseXor, Arel::Nodes::BitwiseNot, Arel::Nodes::BitwiseShiftLeft, Arel::Nodes::BitwiseShiftRight, Arel::Nodes::LessThan, Arel::Nodes::GreaterThan, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual, Arel::Nodes::NotEqual, Arel::Nodes::Contains, Arel::Nodes::ContainedBy, Arel::Nodes::Overlap, Arel::Nodes::Concat, Arel::Nodes::ContainedWithinEquals, Arel::Nodes::ContainsEquals, Arel::Nodes::JsonGetObject, Arel::Nodes::JsonGetField, Arel::Nodes::JsonPathGetObject, Arel::Nodes::JsonPathGetField, Arel::Nodes::JsonbKeyExists, Arel::Nodes::JsonbAnyKeyExists, Arel::Nodes::JsonbAllKeyExists, Arel::Nodes::Regexp, Arel::Nodes::NotRegexp, Arel::Nodes::InfixOperation, Arel::Nodes::UnaryOperation)) } def generate_operator(left, right, operator) left = maybe_add_grouping(left) right = maybe_add_grouping(right) @@ -1077,6 +1132,7 @@ def generate_operator(left, right, operator) end end + sig { params(attribute: T.any(T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Hash[String, T::Hash[String, String]], Integer)]]], T::Hash[String, T::Hash[String, String]]), context: T.nilable(Symbol, T::Boolean)).returns(T.any(String, Integer, Arel::Table, Arel::Nodes::UnboundColumnReference, Arel::Nodes::NamedFunction, Arel::SelectManager, Arel::Nodes::Quoted, Arel::Nodes::Equality, Arel::Nodes::SqlLiteral, Arel::Nodes::Array, Arel::Nodes::TypeCast, Arel::Nodes::SelectStatement, Arel::Nodes::Grouping, Arel::Nodes::Sum, Arel::Nodes::Addition, Arel::Nodes::Subtraction, Arel::Nodes::Multiplication, Arel::Nodes::Division, Arel::Nodes::Modulo, Arel::Nodes::Exponentiation, Arel::Nodes::SquareRoot, Arel::Nodes::CubeRoot, Arel::Nodes::Factorial, Arel::Nodes::Absolute, Arel::Nodes::BitwiseAnd, Arel::Nodes::BitwiseOr, Arel::Nodes::BitwiseXor, Arel::Nodes::BitwiseNot, Arel::Nodes::BitwiseShiftLeft, Arel::Nodes::BitwiseShiftRight, Arel::Nodes::LessThan, Arel::Nodes::GreaterThan, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual, Arel::Nodes::NotEqual, Arel::Nodes::Contains, Arel::Nodes::ContainedBy, Arel::Nodes::Overlap, Arel::Nodes::Concat, Arel::Nodes::ContainedWithinEquals, Arel::Nodes::ContainsEquals, Arel::Nodes::JsonGetObject, Arel::Nodes::JsonGetField, Arel::Nodes::JsonPathGetObject, Arel::Nodes::JsonPathGetField, Arel::Nodes::JsonbKeyExists, Arel::Nodes::JsonbAnyKeyExists, Arel::Nodes::JsonbAllKeyExists, Arel::Nodes::Regexp, Arel::Nodes::NotRegexp, Arel::Nodes::InfixOperation, Arel::Attributes::Attribute, Arel::Nodes::UnaryOperation, Arel::Nodes::CurrentTimestamp, Arel::InsertManager, Arel::Nodes::BindParam, Arel::Nodes::Assignment, Arel::UpdateManager, Arel::Nodes::CurrentDate, Arel::Nodes::CurrentTime, T::Array[T.any(Arel::Nodes::TableAlias, Arel::Nodes::InnerJoin)], Arel::Nodes::LocalTime, Arel::Nodes::LocalTimestamp, Arel::Nodes::NamedArgument, Arel::DeleteManager, Arel::Nodes::Window, Arel::Nodes::Over, Arel::Nodes::Descending, Arel::Nodes::NamedWindow, Arel::Nodes::Row, Arel::Nodes::Ascending, Arel::Nodes::Lock, Arel::Nodes::As, Arel::Nodes::With, Arel::Nodes::Transaction, Arel::Nodes::When, Arel::Nodes::Case, Arel::Nodes::WithRecursive, Arel::Nodes::TableAlias, Arel::Nodes::Indirection, Arel::Nodes::Coalesce, Arel::Nodes::Exists, Arel::Nodes::Avg, Arel::Nodes::In, Arel::Nodes::ArraySubselect, Arel::Nodes::Infer, Arel::Nodes::Conflict, Arel::Nodes::DistinctFrom, Arel::Nodes::NotDistinctFrom, Arel::Nodes::NullIf, Arel::Nodes::NotIn, Arel::Nodes::DoesNotMatch, Arel::Nodes::Matches, Arel::Nodes::Similar, Arel::Nodes::NotSimilar, Arel::Nodes::Between, Arel::Nodes::NotBetween, Arel::Nodes::BetweenSymmetric, Arel::Nodes::NotBetweenSymmetric, Arel::Nodes::CurrentOfExpression, Arel::Nodes::Least, Arel::Nodes::Greatest, Arel::Nodes::And, Arel::Nodes::SetToDefault, Arel::Nodes::VariableShow, Arel::Nodes::Rank, Arel::Nodes::Count, Arel::Nodes::GenerateSeries, Arel::Nodes::Max, Arel::Nodes::Min, Arel::Nodes::VariableSet, Arel::Nodes::Lateral, Arel::Nodes::CurrentRole, Arel::Nodes::CurrentUser, Arel::Nodes::SessionUser, Arel::Nodes::User, Arel::Nodes::CurrentCatalog, Arel::Nodes::CurrentSchema, Arel::Nodes::WithOrdinality, Arel::Nodes::BitString, Arel::Nodes::Or)) } def visit(attribute, context = nil) return attribute.map { |attr| visit(attr, context) } if attribute.is_a? Array @@ -1109,10 +1165,12 @@ def visit(attribute, context = nil) end end + sig { params(object: T::Hash[String, T::Hash[String, String]]).returns(T::Array[T.any(String, T::Hash[String, String])]) } def klass_and_attributes(object) [object.keys.first, object.values.first] end + sig { params(args: T::Array[Arel::Nodes::Grouping], boolean_class: Class).returns(Arel::Nodes::Or) } def generate_boolean_expression(args, boolean_class) chain = boolean_class.new(nil, nil) @@ -1130,6 +1188,7 @@ def generate_boolean_expression(args, boolean_class) chain.right end + sig { params(clause: T::Array[T::Hash[String, T::Hash[String, T.any(String, T::Boolean, Integer)]]]).returns(T::Array[T::Array]) } def generate_sources(clause) froms = [] join_sources = [] @@ -1154,6 +1213,7 @@ def generate_sources(clause) end end + sig { params(sub_link_type: Integer, subselect: Arel::Nodes::SelectStatement, testexpr: Arel::Nodes::UnboundColumnReference, operator: String).returns(T.any(Arel::Nodes::Grouping, Arel::Nodes::LessThanOrEqual, Arel::Nodes::Exists, Arel::Nodes::GreaterThan, Arel::Nodes::Equality, Arel::Nodes::In, Arel::Nodes::ArraySubselect)) } def generate_sublink(sub_link_type, subselect, testexpr, operator) case sub_link_type when PgQuery::SUBLINK_TYPE_EXISTS @@ -1189,6 +1249,7 @@ def generate_sublink(sub_link_type, subselect, testexpr, operator) end end + sig { params(node: T.nilable(Arel::Nodes::UnboundColumnReference, Arel::Nodes::Quoted, Arel::Nodes::Array, Integer, Arel::Nodes::Addition, Arel::Nodes::Subtraction, Arel::Nodes::Multiplication, Arel::Nodes::SqlLiteral, Arel::Nodes::TypeCast, Arel::Nodes::NamedFunction, Arel::Nodes::Concat, Arel::Nodes::Overlap, Arel::Attributes::Attribute, Arel::Nodes::BindParam, Arel::Nodes::Any, T::Array[Arel::Nodes::AtTimeZone], Arel::Nodes::All, Arel::Nodes::Grouping)).returns(T.nilable(Arel::Nodes::UnboundColumnReference, Arel::Nodes::Quoted, Arel::Nodes::Array, Integer, Arel::Nodes::Grouping, Arel::Nodes::SqlLiteral, Arel::Nodes::TypeCast, Arel::Nodes::NamedFunction, Arel::Attributes::Attribute, Arel::Nodes::BindParam, Arel::Nodes::Any, T::Array[Arel::Nodes::AtTimeZone], Arel::Nodes::All)) } def maybe_add_grouping(node) case node when Arel::Nodes::Binary @@ -1198,6 +1259,7 @@ def maybe_add_grouping(node) end end + sig { params(message: String, backtrace: T::Array[String]).returns(T.untyped) } def boom(message, backtrace = nil) new_message = <<~STRING @@ -1221,4 +1283,4 @@ def boom(message, backtrace = nil) # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/AbcSize # rubocop:enable Naming/UncommunicativeMethodParamName -# rubocop:enable Metrics/ParameterLists +# rubocop:enable Metrics/ParameterLists \ No newline at end of file diff --git a/lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb b/lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb index 29e642c1..024fb239 100644 --- a/lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb +++ b/lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb @@ -1,8 +1,10 @@ +# typed: true module Arel module SqlToArel class PgQueryVisitor class FrameOptions class << self + sig { params(frame_options: Integer, start_offset: Integer, end_offset: Integer).returns(T.any(Arel::Nodes::Range, Arel::Nodes::Between, Arel::Nodes::Rows)) } def arel(frame_options, start_offset, end_offset) frame_option_names = calculate_frame_option_names(frame_options) return unless frame_option_names.include?('FRAMEOPTION_NONDEFAULT') @@ -59,6 +61,7 @@ def arel(frame_options, start_offset, end_offset) 'FRAMEOPTION_END_VALUE_FOLLOWING' => 0x02000 }.freeze + sig { params(number: Integer, candidates: T::Array[Integer]).returns(Integer) } def biggest_detractable_number(number, candidates) high_to_low_candidates = candidates.sort { |a, b| b <=> a } high_to_low_candidates.find do |candidate| @@ -66,6 +69,7 @@ def biggest_detractable_number(number, candidates) end end + sig { params(frame_options: Integer, names: T::Array[String]).returns(T::Array[String]) } def calculate_frame_option_names(frame_options, names = []) return names if frame_options.zero? @@ -76,14 +80,16 @@ def calculate_frame_option_names(frame_options, names = []) ) end + sig { params(pattern: String, frame_option_names: T::Array[String], offset: Integer).returns(T.any(Arel::Nodes::CurrentRow, Arel::Nodes::Preceding, Arel::Nodes::Following)) } def calculate_frame_node(pattern, frame_option_names, offset) node_name = frame_option_names.select { |n| n.start_with?(pattern) } raise "Don't know how to handle multiple nodes" if node_name.length > 1 - node_name = node_name.first.gsub(/FRAMEOPTION_(START|END)_/, '') + node_name = T.must(node_name.first).gsub(/FRAMEOPTION_(START|END)_/, '') name_to_node(node_name, offset) end + sig { params(node_name: String, offset: Integer).returns(T.any(Arel::Nodes::CurrentRow, Arel::Nodes::Preceding, Arel::Nodes::Following)) } def name_to_node(node_name, offset) case node_name when 'UNBOUNDED_PRECEDING' @@ -109,4 +115,4 @@ def name_to_node(node_name, offset) end end end -end +end \ No newline at end of file diff --git a/lib/arel/sql_to_arel/result.rb b/lib/arel/sql_to_arel/result.rb index 8f8d0544..34c8cd4f 100644 --- a/lib/arel/sql_to_arel/result.rb +++ b/lib/arel/sql_to_arel/result.rb @@ -1,17 +1,21 @@ +# typed: true module Arel module SqlToArel class Result < Array + sig { returns(String) } def to_sql map(&:to_sql).join('; ') end + sig { returns(String) } def to_formatted_sql map(&:to_formatted_sql).join('; ') end + sig { params(block: Proc).returns(Arel::SqlToArel::Result) } def map(&block) Result.new super end end end -end +end \ No newline at end of file diff --git a/lib/arel_toolkit.rb b/lib/arel_toolkit.rb index b89ae719..358e042b 100644 --- a/lib/arel_toolkit.rb +++ b/lib/arel_toolkit.rb @@ -1,3 +1,4 @@ +# typed: strict # Make sure the extensions are loaded before ArelToolkit require 'postgres_ext' if Gem.loaded_specs.key?('postgres_ext') require 'active_record_upsert' if Gem.loaded_specs.key?('active_record_upsert') @@ -11,4 +12,4 @@ require 'arel/sql_formatter' module ArelToolkit -end +end \ No newline at end of file diff --git a/lib/arel_toolkit/version.rb b/lib/arel_toolkit/version.rb index da5bf6de..339c40a3 100644 --- a/lib/arel_toolkit/version.rb +++ b/lib/arel_toolkit/version.rb @@ -1,3 +1,4 @@ +# typed: true module ArelToolkit VERSION = '0.3.0'.freeze -end +end \ No newline at end of file