twirp-on-rails 1.0.0 → 1.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bb31fa12f51069d7d6e447901646dd1ebfdc657d59bc670fffc57f8f858b34e
4
- data.tar.gz: 414f84e6b7b655fabad364721fc6ea31ee94300674303ff633b5bf49434610cd
3
+ metadata.gz: 2925a659b9c79db0bfced51d9f8e8c3c86a9c9b4977f64611f7f57d7b2597c00
4
+ data.tar.gz: 56abcb2fa1e40241eef7f3199529bf4a83971f82358f679526a38b482c12cb79
5
5
  SHA512:
6
- metadata.gz: 986ee79625c2cea727ebbb09b0efb0f110a5e64f3ce5d186dfd2786ceb35d48f88935a43335f4c6740144fa6023cc12107288554d2a3389f37bf3f6ad2b01f21
7
- data.tar.gz: 68c86eb0918f123e6b96457944347893f96bdfbabe91c4c3f1bd8b0ae75c6eac3b590856f6156c3488ade4a58ebcc906dc566b8c255326da3eb89344796e4a5f
6
+ metadata.gz: 28a1b6ec586b9e129a64390a5e727aee495a2c624d74ca9b94ac0a1548b5fd36d4951a6e1bc256ca560ea3909a45c4e637dce401a8a77953d2faa6628644674e
7
+ data.tar.gz: 661c948ab6ca8b80d83fd882581d4e1246e541aebb2416e62fcafa1f202454453d8ccd7dadcb9ef0b6b8171eefef68aa19794d647595d2fe1a49e7c35fd8a0d4
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://img.shields.io/gem/v/twirp-on-rails.svg)](https://rubygems.org/gems/twirp-on-rails)
1
2
  [![CI](https://github.com/collectiveidea/twirp-rails/actions/workflows/ci.yml/badge.svg)](https://github.com/collectiveidea/twirp-rails/actions/workflows/ci.yml)
2
3
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
3
4
 
@@ -5,21 +6,19 @@
5
6
 
6
7
  ## Motivation
7
8
 
8
- Make serving [Twirp](https://twitchtv.github.io/twirp/) RPC Services as easy and familiar as Rails controllers. Add a few helpful abstractions, but don't hide [Twirp](https://twitchtv.github.io/twirp/), [Protobufs](https://protobuf.dev), or make it seem too magical.
9
+ Serving [Twirp](https://twitchtv.github.io/twirp/) RPC Services should be as easy and familiar as Rails controllers. We add a few helpful abstractions, but don't hide [Twirp](https://twitchtv.github.io/twirp/), [Protobufs](https://protobuf.dev), or make it seem too magical.
9
10
 
10
- Out of the box, the [`twirp` gem](http://github.com/github/twirp-ruby) makes it easy to add [Services](https://github.com/github/twirp-ruby/wiki/Service-Handlers), but it feels clunky coming from Rails REST-ful APIs. We make it simple to build full-featured APIs. Hook in authorization, use `before_action` and more.
11
+ Out of the box, the [`twirp` gem](http://github.com/github/twirp-ruby) lets you add [Services](https://github.com/github/twirp-ruby/wiki/Service-Handlers), but it feels clunky coming from Rails REST-ful APIs. We make it simple to build full-featured APIs. Hook in authorization, use `before_action` and more.
11
12
 
12
13
  Extracted from a real, production application with many thousands of users.
13
14
 
14
15
  ## Installation
15
16
 
16
- Install the gem and add to the application's Gemfile by executing:
17
+ Install the gem using `gem install twirp-on-rails` or simply add it to your `Gemfile`:
17
18
 
18
- $ bundle add twirp-on-rails
19
-
20
- If bundler is not being used to manage dependencies, install the gem by executing:
21
-
22
- $ gem install twirp-on-rails
19
+ ```
20
+ gem "twirp-on-rails"
21
+ ```
23
22
 
24
23
  ## Usage
25
24
 
@@ -29,6 +28,20 @@ Add to your `routes.rb`:
29
28
  mount Twirp::Rails::Engine, at: "/twirp"
30
29
  ```
31
30
 
31
+ ### Generate your `_pb.rb` and `_twirp.rb` files
32
+
33
+ Generate files [how Twirp-Ruby recommends](https://github.com/arthurnn/twirp-ruby/wiki/Code-Generation).
34
+
35
+ Example:
36
+
37
+ ```bash
38
+ protoc --ruby_out=./lib --twirp_ruby_out=./lib haberdasher.proto
39
+ ```
40
+
41
+ We (currently) don't run `protoc` for you and have no opinions where you put the generated files.
42
+
43
+ Ok, one small opinion: we default to looking in `lib/`, but you can change that.
44
+
32
45
  ### Configuration
33
46
 
34
47
  Twirp::Rails will automatically load any `*_twirp.rb` files in your app's `lib/` directory (and subdirectories). To modify the location, add this to an initializer:
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rack/conditional_get"
4
+ require "rack/version"
4
5
 
5
6
  module Twirp
6
7
  module Rails
@@ -29,18 +30,21 @@ module Twirp
29
30
  def call(env)
30
31
  case env[::Rack::REQUEST_METHOD]
31
32
  when "POST"
32
- status, headers, body = @app.call(env)
33
- headers = ::Rack::Utils::HeaderHash[headers]
33
+ status, headers, body = response = @app.call(env)
34
+ # Rack 3 settles on only allowing lowercase headers
35
+ if Rack.release < "3.0"
36
+ headers = ::Rack::Utils::HeaderHash[headers]
37
+ end
38
+
34
39
  if status == 200 && fresh?(env, headers)
35
- status = 304
40
+ response[0] = 304
36
41
  headers.delete(::Rack::CONTENT_TYPE)
37
42
  headers.delete(::Rack::CONTENT_LENGTH)
38
- original_body = body
39
- body = ::Rack::BodyProxy.new([]) do
40
- original_body.close if original_body.respond_to?(:close)
43
+ response[2] = Rack::BodyProxy.new([]) do
44
+ body.close if body.respond_to?(:close)
41
45
  end
42
46
  end
43
- [status, headers, body]
47
+ response
44
48
  else
45
49
  @app.call(env)
46
50
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Twirp
4
4
  module Rails
5
- VERSION = "1.0.0"
5
+ VERSION = "1.0.1.pre"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twirp-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Morrison
8
8
  - Darron Schall
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-05-08 00:00:00.000000000 Z
12
+ date: 2024-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -73,7 +73,7 @@ metadata:
73
73
  homepage_uri: https://github.com/collectiveidea/twirp-rails
74
74
  source_code_uri: https://github.com/collectiveidea/twirp-rails
75
75
  changelog_uri: https://github.com/collectiveidea/twirp-rails/blob/main/CHANGELOG.md
76
- post_install_message:
76
+ post_install_message:
77
77
  rdoc_options: []
78
78
  require_paths:
79
79
  - lib
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubygems_version: 3.5.9
92
- signing_key:
92
+ signing_key:
93
93
  specification_version: 4
94
94
  summary: Use Twirp RPC with Rails
95
95
  test_files: []