Skip to content

Commit

Permalink
Add RBS support for Ruby 3+
Browse files Browse the repository at this point in the history
  • Loading branch information
splittingred committed Dec 30, 2021
1 parent f381f3d commit e7d0803
Show file tree
Hide file tree
Showing 57 changed files with 1,393 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*.gem
/vendor/bundle
bundler.lock
/.gem_rbs_collection/
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AllCops:
- spec/fixtures/**/*
- spec/pb/**/*
- spec/demo_server
- ./**/*.rbs
require:
- rubocop-performance
- rubocop-rspec
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Changelog for the gruf gem. This includes internal history before the gem was ma

### Pending release

- Add RBS support for Ruby 3.0
-
### 2.12.0

- Fixed interceptor order to be FIFO as documented, instead of FILO (fixes #139)
Expand Down
20 changes: 20 additions & 0 deletions lib/gruf.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
VERSION: ::String
end
4 changes: 4 additions & 0 deletions lib/gruf/cli/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module Cli
class Executor
##
# @param [Hash|ARGV]
# @param [::Gruf::Server|NilClass] server
# @param [::Array|NilClass] services
# @param [::Gruf::Hooks::Executor|NilClass] hook_executor
# @param [::Logger|NilClass] logger
#
def initialize(
args = ARGV,
Expand Down
28 changes: 28 additions & 0 deletions lib/gruf/cli/executor.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
module Cli
class Executor
def initialize: (?(Hash | ::ARGV) args, ?server: ::Gruf::Server? server, ?services: Array? services, ?hook_executor: ::Gruf::Hooks::Executor? hook_executor, ?logger: ::Logger? logger) -> void
def run: () -> void

private

def setup!: () -> void
def parse_options: () -> ::Slop::Result
end
end
end
6 changes: 5 additions & 1 deletion lib/gruf/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def rpc_desc(request_method)
#
# @param [Symbol] request_method The method name being called on the remote service
# @param [Hash] params (Optional) A hash of parameters that will populate the request object
# @return [Class] The request object that corresponds to the method being called
# @return [Object] The request object that corresponds to the method being called
# @return [NilClass]
#
def request_object(request_method, params = {})
desc = rpc_desc(request_method)
Expand All @@ -165,6 +166,7 @@ def request_object(request_method, params = {})
# Properly find the appropriate call signature for the GRPC::GenericService given the request method name
#
# @return [Symbol]
# @return [NilClass]
#
def call_signature(request_method)
desc = rpc_desc(request_method)
Expand Down Expand Up @@ -227,6 +229,8 @@ def error_deserializer_class
# @param [mixed] timeout
# @return [Float]
# @return [GRPC::Core::TimeSpec]
# @return [Numeric]
# @return [Integer]
#
def parse_timeout(timeout)
if timeout.nil?
Expand Down
38 changes: 38 additions & 0 deletions lib/gruf/client.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
class Client < ::SimpleDelegator
attr_reader base_klass: ::Class
attr_reader service_klass: ::Class
attr_reader opts: ::Hash[::Symbol, ::Object]

def initialize: (service: ::Module service, ?options: ::Hash[::Symbol, ::Object] options, ?client_options: ::Hash[::Symbol, ::Object] client_options) -> void
def call: (::Symbol request_method, ?::Hash[::Symbol, ::Object] params, ?::Hash[::Symbol, ::Object] metadata, ?::Hash[::Symbol, ::Object] opts) { () -> ::Object } -> ::Gruf::Response
def timeout: () -> ( Integer | Float | Numeric | ::GRPC::Core::TimeSpec | nil )

private

def streaming_request?: (Symbol request_method) -> bool
def execute: (::Symbol call_sig, ?Object req, ?Hash[::Symbol, ::Object] metadata, ?::Hash[::Symbol, ::Object] opts) { () -> Object } -> ::Array[::Gruf::Timer::Result, ::GRPC::ActiveCall::Operation]
def rpc_desc: (::Symbol request_method) -> ::GRPC::RpcDesc
def request_object: (::Symbol request_method, ?::Hash[::Symbol, ::Object] params) -> ( ::Class | nil )
def call_signature: (::Symbol request_method) -> ( ::Symbol | nil )
def build_metadata: (?::Hash[::Symbol, ::Object] metadata) -> ::Hash[::Symbol, ::Object]
def build_ssl_credentials: () -> ( Symbol | GRPC::Core::ChannelCredentials)
def error_deserializer_class: () -> ::Class
def parse_timeout: (untyped timeout) -> ( ::Float | ::Numeric | ::Integer | ::GRPC::Core::TimeSpec )
end
end
82 changes: 82 additions & 0 deletions lib/gruf/client/error.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
class Client < ::SimpleDelegator
class Error < ::StandardError
attr_reader error: Object
def initialize: (Object error) -> void
end

module Errors
class Base < Gruf::Client::Error
end

class Error < Base
end

class Validation < Base
end

class Ok < Base
end

class InvalidArgument < Validation
end

class NotFound < Validation
end

class AlreadyExists < Validation
end

class OutOfRange < Validation
end

class Cancelled < Error
end

class DataLoss < Error
end

class DeadlineExceeded < Error
end

class FailedPrecondition < Error
end

class Internal < Error
end

class PermissionDenied < Error
end

class ResourceExhausted < Error
end

class Unauthenticated < Error
end

class Unavailable < Error
end

class Unimplemented < Error
end

class Unknown < Error
end
end
end
end
6 changes: 4 additions & 2 deletions lib/gruf/client/error_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def initialize(
# coalesce them.
#
# @param [Exception] exception
# @return [Gruf::Client::Errors::Base|SignalException]
# @return [Gruf::Client::Errors::Base]
# @return [SignalException]
# @return [Exception]
#
def from_exception(exception)
# passthrough on Signals, we don't want to mess with these
Expand Down Expand Up @@ -78,7 +80,7 @@ def deserialize(exception)

##
# @param [Exception] exception
# @return [Gruf::Client::Errors::Base]
# @return [::Class]
#
def determine_class(exception)
error_class = Gruf::Client::Errors.const_get(exception.class.name.demodulize)
Expand Down
29 changes: 29 additions & 0 deletions lib/gruf/client/error_factory.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
class Client < ::SimpleDelegator
class ErrorFactory
def initialize: (?default_class: ::Class? default_class, ?deserializer_class: ::Class? deserializer_class, ?metadata_key: (Symbol | String)? metadata_key) -> void
def from_exception: (::Exception exception) -> ( ::Gruf::Client::Errors::Base | SignalException | Exception )

private

def deserialize: (::Gruf::Client::Errors::Base exception) -> String
def determine_class: (::Exception exception) -> ::Class
def default_serializer: () -> ::Gruf::Serializers::Errors::Base
end
end
end
32 changes: 32 additions & 0 deletions lib/gruf/configuration.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
module Configuration
VALID_CONFIG_KEYS: ::Hash[::Symbol, ::Object]

def self.extended: (::Gruf::Configuration base) -> void

def configure: () { () -> ::Gruf::Configuration } -> ::Gruf::Configuration

def options: () -> ::Hash

def reset: () -> ::Hash

private

def environment: () -> ::String
end
end
29 changes: 29 additions & 0 deletions lib/gruf/controllers/base.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
module Controllers
class Base
attr_reader request: ::Gruf::Controller::Request
attr_reader error: ::Gruf::Error
attr_reader self.bound_service: ::GRPC::GenericService

def initialize: (method_key: ::Symbol method_key, service: ::GRPC::GenericService service, rpc_desc: ::GRPC::RpcDesc rpc_desc, active_call: ::GRPC::ActiveCall active_call, message: ::Object message) -> void
def self.bind: (::GRPC::GenericService service) -> void
def process_action: (::Symbol method_key) { () -> ::Object } -> ::Object
def call: (::Symbol method_key) { () -> ::Object } -> ::Object
end
end
end
37 changes: 37 additions & 0 deletions lib/gruf/controllers/request.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module Gruf
module Controllers
class Request
attr_reader message: ::Object
attr_reader active_call: ::GRPC::ActiveCall
attr_reader method_key: ::Symbol
attr_reader type: ::Gruf::Controllers::Request::Type
attr_reader service: ::Class

class Type
def initialize: (::GRPC::RpcDesc rpc_desc) -> void
end

def initialize: (method_key: ::Symbol method_key, service: ::Class service, rpc_desc: ::GRPC::RpcDesc rpc_desc, active_call: ::GRPC::ActiveCall active_call, message: ::Object message) -> void
def service_key: () -> ::String
def response_class: () -> ::Class
def request_class: () -> ::Class
def method_name: () -> ::String
def messages: () -> (::Enumerable[::Object] | ::Object)
end
end
end
Loading

0 comments on commit e7d0803

Please sign in to comment.