Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Sorbet! Tasty #95

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion lib/arel/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: strict
require 'arel/extensions/unknown'
require 'arel/extensions/time_with_precision'
require 'arel/extensions/current_time'
Expand Down Expand Up @@ -98,4 +99,4 @@
module Arel
module Extensions
end
end
end
4 changes: 3 additions & 1 deletion lib/arel/extensions/absolute.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/arel/extensions/all.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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
Expand All @@ -20,4 +22,4 @@ def visit_Arel_Nodes_All(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/any.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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
Expand All @@ -20,4 +22,4 @@ def visit_Arel_Nodes_Any(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
5 changes: 4 additions & 1 deletion lib/arel/extensions/array.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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()

Expand All @@ -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, ', ')
Expand All @@ -26,4 +29,4 @@ def visit_Arel_Nodes_Array(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/array_subselect.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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
Expand All @@ -20,4 +22,4 @@ def visit_Arel_Nodes_ArraySubselect(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/assignment.rb
Original file line number Diff line number Diff line change
@@ -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 << ' = '
Expand All @@ -19,4 +21,4 @@ def visit_Arel_Nodes_Assignment(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
5 changes: 4 additions & 1 deletion lib/arel/extensions/at_time_zone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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)

Expand All @@ -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 '
Expand All @@ -27,4 +30,4 @@ def visit_Arel_Nodes_AtTimeZone(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/between_symmetric.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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 '
Expand All @@ -20,4 +22,4 @@ def visit_Arel_Nodes_BetweenSymmetric(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
5 changes: 4 additions & 1 deletion lib/arel/extensions/bit_string.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -6,6 +7,7 @@ module Nodes
class BitString < Arel::Nodes::Node
attr_reader :str

sig { params(str: String).void }
def initialize(str)
super()

Expand All @@ -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
Expand All @@ -24,4 +27,4 @@ def visit_Arel_Nodes_BitString(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/bitwise_xor.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/arel/extensions/coalesce.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/arel/extensions/conflict.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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 '

Expand Down Expand Up @@ -44,4 +46,4 @@ def visit_Arel_Nodes_Conflict(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/contained_by.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/arel/extensions/contained_within_equals.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion lib/arel/extensions/contains.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# typed: false
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

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
Expand All @@ -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
Expand All @@ -29,4 +32,4 @@ def initialize(left, right)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/contains_equals.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/arel/extensions/cross_join.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

Expand All @@ -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
Expand All @@ -18,4 +20,4 @@ def visit_Arel_Nodes_CrossJoin(o, collector)
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Naming/UncommunicativeMethodParamName
4 changes: 3 additions & 1 deletion lib/arel/extensions/cube_root.rb
Original file line number Diff line number Diff line change
@@ -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
Loading