gritz 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +112 -0
- data/exe/gritz +6 -0
- data/lib/gritz/version.rb +5 -0
- data/lib/gritz.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cb226dd8bf426c8d12c7f625ea6966c9934939253ae52dab3ccc7994fa465a71
|
|
4
|
+
data.tar.gz: cff37f83aadc7ebaccfefcbc6b1f1dc49aa928279bedb621cbfd406b0ac374df
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 79f29f7b897f4dd4ac1e19a10e0e5b650dd4071996403d033a3d1cde5a6687401adb2179c8db9245b2abda817ccd9e9459dd07a407fb98915c459e17b08fbcc6
|
|
7
|
+
data.tar.gz: 91a6b189a9486d3978a084e99c3e4534dfa3238b4c8aa38f53c224ea95c1ba7e8598af5c2460ae9fb033466ddce18a8bc7155db0813c664e7c9b08a721d9e90a
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yudai Takada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Gritz
|
|
2
|
+
|
|
3
|
+
Gritz is a Ruby gRPC application framework with controllers, middleware and network-free controller tests. It supports a single-process C-core server and all four RPC forms: unary, server streaming, client streaming and bidirectional streaming.
|
|
4
|
+
|
|
5
|
+
Requires CRuby 3.3 or later and grpc 1.83 or later. Linux and macOS are tested.
|
|
6
|
+
|
|
7
|
+
## Packages
|
|
8
|
+
|
|
9
|
+
| Gem | Repository | Role |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `gritz` | [gritzrpc/gritz](https://github.com/gritzrpc/gritz) | Default combination and executable |
|
|
12
|
+
| `gritz-core` | [gritzrpc/gritz-core](https://github.com/gritzrpc/gritz-core) | Transport-independent application framework |
|
|
13
|
+
| `gritz-native` | [gritzrpc/gritz-native](https://github.com/gritzrpc/gritz-native) | Official grpc gem adapter and thread pool |
|
|
14
|
+
|
|
15
|
+
After v0.1.0 is published, applications can add `gem "gritz", "~> 0.1.0"` to their Gemfile. It installs both the core and native adapter. The Fiber adapter `gritz-async` and integrations `gritz-rails` / `gritz-otel` are planned.
|
|
16
|
+
|
|
17
|
+
## Quickstart from source
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/gritzrpc/gritz.git
|
|
21
|
+
cd gritz
|
|
22
|
+
bundle install
|
|
23
|
+
bundle exec ruby exe/gritz routes -C examples/hello/config/gritz.rb
|
|
24
|
+
bundle exec ruby exe/gritz start -C examples/hello/config/gritz.rb
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
In another terminal, run `bundle exec ruby examples/hello/client.rb`. It calls all four RPC forms. To use grpcurl, supply the bundled proto:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
grpcurl -plaintext -import-path examples/hello/proto -proto hello.proto \
|
|
31
|
+
-d '{"name":"Ruby"}' localhost:50051 helloworld.Greeter/SayHello
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Controllers
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
class GreeterController < Gritz::Controller
|
|
38
|
+
bind Helloworld::Greeter::Service
|
|
39
|
+
|
|
40
|
+
def say_hello
|
|
41
|
+
fail!(:invalid_argument, "name is required") if request.message.name.empty?
|
|
42
|
+
Helloworld::HelloReply.new(message: "Hello, #{request.message.name}!")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def chat
|
|
46
|
+
request.each_message do |message|
|
|
47
|
+
stream.write(Helloworld::HelloReply.new(message: message.name.upcase))
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Register controllers in a configuration file:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
require_relative "../app/greeter_controller"
|
|
57
|
+
|
|
58
|
+
workers 0
|
|
59
|
+
threads 16
|
|
60
|
+
bind "127.0.0.1:50051"
|
|
61
|
+
register_controller GreeterController
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Set `strict_routes true` once every RPC in the bound service has an action; otherwise missing actions return `UNIMPLEMENTED`.
|
|
65
|
+
|
|
66
|
+
`before_action`, `around_action`, `after_action` and `rescue_from` support inheritance. Each RPC gets its own controller instance. `Gritz::Context.current` carries metadata, deadline, peer, request ID and a per-request store; child fibers and threads inherit it. Requests exceeding their deadline are rejected cooperatively at request reads and response writes. `context.check_deadline!` can also be called during application work.
|
|
67
|
+
|
|
68
|
+
The default middleware adds request IDs, scopes context, writes JSON completion logs and converts exceptions to gRPC errors. Internal errors expose an `error-id` trailer rather than application exception messages. `fail!` accepts status symbols, trailing metadata and protobuf rich error details. Middleware wraps the full stream, including incremental response writes.
|
|
69
|
+
|
|
70
|
+
## Testing
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
require "gritz/testing/rspec"
|
|
74
|
+
|
|
75
|
+
RSpec.describe GreeterController, type: :rpc do
|
|
76
|
+
it "greets a user" do
|
|
77
|
+
reply = rpc(:say_hello, Helloworld::HelloRequest.new(name: "Ruby"))
|
|
78
|
+
expect(reply.message).to eq("Hello, Ruby!")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "validates names" do
|
|
82
|
+
expect { rpc(:say_hello, Helloworld::HelloRequest.new) }
|
|
83
|
+
.to raise_rpc_error(:invalid_argument)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Minitest tests can include `Gritz::Testing::Minitest` after requiring `gritz/testing/minitest`; pass `controller:` to `rpc` and use `assert_rpc_error`. `Gritz::Testing::Server.start(controllers: [GreeterController]) { |server| ... }` starts a real server on an ephemeral port and stops it when the block exits.
|
|
89
|
+
|
|
90
|
+
## Configuration and limitations
|
|
91
|
+
|
|
92
|
+
Configuration precedence is CLI options, `GRITZ_*` environment variables, configuration file, then defaults. See the [configuration guide](docs/guides/configuration.md) for settings and lifecycle hooks.
|
|
93
|
+
|
|
94
|
+
Use `TERM` or `INT` to finish in-flight calls within `shutdown_timeout`; `QUIT` closes immediately. Application code should check deadlines and cancellation during long work. The grpc 1.83 server view can report cancellation late; deadlines remain the practical limit for long handlers. The native thread pool rejects excess requests immediately with `RESOURCE_EXHAUSTED`; grpc 1.83 ignores its deprecated `max_waiting_requests` setting.
|
|
95
|
+
|
|
96
|
+
The server binds insecure gRPC sockets. Use a trusted network or a TLS-terminating proxy. Native TLS, health checks, reflection, metrics export and multi-process supervision are unavailable. Unsupported transport, worker and TLS features fail at startup.
|
|
97
|
+
|
|
98
|
+
The default transport is `:native` (`Gritz::Transport::Native`). `gritz-core` can be loaded separately with `require "gritz/core"` without loading grpc.
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
Each repository has its own tests, CI and package build. Development dependencies come from their Git repositories; sibling checkouts are optional. See [CONTRIBUTING.md](CONTRIBUTING.md) to work on local components.
|
|
103
|
+
|
|
104
|
+
Run `bundle exec rake`, `COVERAGE=1 bundle exec rspec`, `bundle exec rubocop` and `bundle exec rake build`. The [Linux devcontainer](.devcontainer/devcontainer.json) includes grpcurl and ghz. See the [release guide](docs/guides/releasing.md) for publishing packages.
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/gritzrpc/gritz). See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/gritz
ADDED
data/lib/gritz.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gritz
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yudai Takada
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: gritz-core
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - '='
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.1.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - '='
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.1.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: gritz-native
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - '='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.1.0
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - '='
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.1.0
|
|
40
|
+
description: Gritz combines transport-independent controllers, middleware and testing
|
|
41
|
+
with a gRPC C-core server.
|
|
42
|
+
email:
|
|
43
|
+
- t.yudai92@gmail.com
|
|
44
|
+
executables:
|
|
45
|
+
- gritz
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- CHANGELOG.md
|
|
50
|
+
- LICENSE.txt
|
|
51
|
+
- README.md
|
|
52
|
+
- exe/gritz
|
|
53
|
+
- lib/gritz.rb
|
|
54
|
+
- lib/gritz/version.rb
|
|
55
|
+
homepage: https://github.com/gritzrpc/gritz
|
|
56
|
+
licenses:
|
|
57
|
+
- MIT
|
|
58
|
+
metadata:
|
|
59
|
+
allowed_push_host: https://rubygems.org
|
|
60
|
+
source_code_uri: https://github.com/gritzrpc/gritz
|
|
61
|
+
changelog_uri: https://github.com/gritzrpc/gritz/blob/main/CHANGELOG.md
|
|
62
|
+
rubygems_mfa_required: 'true'
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '3.3'
|
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
requirements: []
|
|
77
|
+
rubygems_version: 4.0.16
|
|
78
|
+
specification_version: 4
|
|
79
|
+
summary: A controller-based Ruby gRPC application framework
|
|
80
|
+
test_files: []
|