rails_twirp 0.3.0 → 0.4.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 +4 -4
- data/lib/rails_twirp/base.rb +8 -3
- data/lib/rails_twirp/engine.rb +19 -4
- data/lib/rails_twirp/testing/integration_test.rb +3 -1
- data/lib/rails_twirp/url_for.rb +17 -0
- data/lib/rails_twirp/version.rb +1 -1
- data/test/dummy/app/controllers/pings_controller.rb +2 -1
- data/test/dummy/app/helpers/random_helper.rb +5 -0
- data/test/dummy/app/{twirp/views → views}/pings/ping_template.pb.pbbuilder +0 -0
- data/test/ping_controller_test.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57a19d4ec190c08eaece39ae6867d9aee3f2b83a3196384f8b0a16c03fbf9739
|
4
|
+
data.tar.gz: 225ce5477525001c7c401af85a98e68d3fe7543bcf20e2fa9bdcd13f34a77a4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7991a7f8707e4f6b28055808edc662c1ec93a9723b059421621cdf0cc461704bc766abeea63e9881382675280f6321b4e3cba941527a684a920733be3ce7a977
|
7
|
+
data.tar.gz: ea05bca838330b1526da0a6844783d7b5f9ab6cd2403050c318670f2d7a96b8c892d017c2b052b99f5063dde40331cf7b4486b084764adf85613c84c6b8e0da0
|
data/lib/rails_twirp/base.rb
CHANGED
@@ -7,7 +7,9 @@ require "abstract_controller/asset_paths"
|
|
7
7
|
require "abstract_controller/caching"
|
8
8
|
require "abstract_controller/logger"
|
9
9
|
require "abstract_controller/callbacks"
|
10
|
+
require "action_controller/metal/helpers"
|
10
11
|
require "rails_twirp/rescue"
|
12
|
+
require "rails_twirp/url_for"
|
11
13
|
|
12
14
|
module RailsTwirp
|
13
15
|
class Base < AbstractController::Base
|
@@ -16,15 +18,18 @@ module RailsTwirp
|
|
16
18
|
# The order of these includes matter.
|
17
19
|
# The rendering modules extend each other, so need to be in this order.
|
18
20
|
include AbstractController::Rendering
|
19
|
-
include ActionView::Rendering
|
20
|
-
include RenderPb
|
21
|
-
include Errors
|
22
21
|
|
23
22
|
# These add helpers for the controller
|
23
|
+
include ActionController::Helpers
|
24
|
+
include UrlFor
|
24
25
|
include AbstractController::AssetPaths
|
25
26
|
include AbstractController::Caching
|
26
27
|
include AbstractController::Logger
|
27
28
|
|
29
|
+
include ActionView::Rendering
|
30
|
+
include RenderPb
|
31
|
+
include Errors
|
32
|
+
|
28
33
|
# These need to be last so errors can be handled as early as possible.
|
29
34
|
include AbstractController::Callbacks
|
30
35
|
include Rescue
|
data/lib/rails_twirp/engine.rb
CHANGED
@@ -15,25 +15,40 @@ module RailsTwirp
|
|
15
15
|
end
|
16
16
|
|
17
17
|
initializer "rails_twirp.logger" do
|
18
|
-
# This hook is called
|
18
|
+
# This hook is called when RailsTwirp::Base is initialized, and it sets the logger
|
19
19
|
ActiveSupport.on_load(:rails_twirp) { self.logger ||= Rails.logger }
|
20
20
|
end
|
21
21
|
|
22
22
|
initializer :add_paths, before: :bootstrap_hook do |app|
|
23
23
|
app.config.paths.add "config/twirp/routes.rb"
|
24
24
|
app.config.paths.add "config/twirp/routes", glob: "**/*.rb"
|
25
|
-
app.config.paths.add "app/twirp/controllers", eager_load: true
|
26
25
|
app.config.paths.add "proto", load_path: true
|
27
|
-
app.config.paths.add "app/twirp/views", load_path: true
|
28
26
|
end
|
29
27
|
|
30
28
|
initializer :set_controller_view_path do |app|
|
31
|
-
views = app.config.paths["app/
|
29
|
+
views = app.config.paths["app/views"].existent
|
32
30
|
unless views.empty?
|
33
31
|
ActiveSupport.on_load(:rails_twirp) { prepend_view_path views }
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
35
|
+
initializer "rails_twirp.helpers" do |app|
|
36
|
+
ActiveSupport.on_load(:rails_twirp) do
|
37
|
+
# Load all the application helpers into the controller
|
38
|
+
include app.routes.mounted_helpers
|
39
|
+
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes, false)
|
40
|
+
extend ::ActionController::Railties::Helpers
|
41
|
+
define_singleton_method(:inherited) do |klass|
|
42
|
+
super(klass)
|
43
|
+
|
44
|
+
# Have to call this explicitely, because ::ActionController::Railties::Helpers
|
45
|
+
# checks if ActionController::Base is a parent class, which it isn't.
|
46
|
+
# If we don't call this, the helpers don't get loaded
|
47
|
+
klass.helper :all
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
37
52
|
initializer :add_twirp do |app|
|
38
53
|
# Here we add the 'twirp' method to application, which is accessible at Rails.application.twirp
|
39
54
|
app.extend TwirpValue
|
@@ -21,7 +21,9 @@ module RailsTwirp
|
|
21
21
|
@request = request
|
22
22
|
service = app.twirp.routes.services[service].to_service
|
23
23
|
|
24
|
-
rack_env = {
|
24
|
+
rack_env = {
|
25
|
+
"HTTP_HOST" => "localhost"
|
26
|
+
}
|
25
27
|
http_request = ActionDispatch::Request.new(rack_env)
|
26
28
|
http_request.headers.merge! headers if headers.present?
|
27
29
|
env = {rack_env: rack_env}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "abstract_controller/url_for"
|
2
|
+
|
3
|
+
module RailsTwirp
|
4
|
+
module UrlFor
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include AbstractController::UrlFor
|
8
|
+
|
9
|
+
def url_options
|
10
|
+
@_url_options ||= {
|
11
|
+
host: http_request.host,
|
12
|
+
port: http_request.optional_port,
|
13
|
+
protocol: http_request.protocol
|
14
|
+
}.merge!(super).freeze
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rails_twirp/version.rb
CHANGED
@@ -7,7 +7,8 @@ class PingsController < ApplicationTwirpController
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def ping_render
|
10
|
-
|
10
|
+
url = rails_twirp_engine_url
|
11
|
+
response = RPC::DummyAPI::PingResponse.new(double_name: "#{url} #{helpers.does_this_work(request.name)}")
|
11
12
|
render pb: response
|
12
13
|
end
|
13
14
|
|
File without changes
|
@@ -11,7 +11,7 @@ class PingControllerTest < RailsTwirp::IntegrationTest
|
|
11
11
|
req = RPC::DummyAPI::PingRequest.new(name: "Bouke")
|
12
12
|
rpc RPC::DummyAPI::DummyService, "PingRender", req
|
13
13
|
refute_instance_of Twirp::Error, response
|
14
|
-
assert_equal "BoukeBouke", response.double_name
|
14
|
+
assert_equal "http://localhost/twirp BoukeBouke", response.double_name
|
15
15
|
end
|
16
16
|
|
17
17
|
test "you can ping template" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_twirp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bouke van der Bijl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/rails_twirp/rescue.rb
|
64
64
|
- lib/rails_twirp/route_set.rb
|
65
65
|
- lib/rails_twirp/testing/integration_test.rb
|
66
|
+
- lib/rails_twirp/url_for.rb
|
66
67
|
- lib/rails_twirp/version.rb
|
67
68
|
- rails_twirp.gemspec
|
68
69
|
- test/dummy/Rakefile
|
@@ -76,15 +77,16 @@ files:
|
|
76
77
|
- test/dummy/app/controllers/concerns/.keep
|
77
78
|
- test/dummy/app/controllers/pings_controller.rb
|
78
79
|
- test/dummy/app/helpers/application_helper.rb
|
80
|
+
- test/dummy/app/helpers/random_helper.rb
|
79
81
|
- test/dummy/app/javascript/packs/application.js
|
80
82
|
- test/dummy/app/jobs/application_job.rb
|
81
83
|
- test/dummy/app/mailers/application_mailer.rb
|
82
84
|
- test/dummy/app/models/application_record.rb
|
83
85
|
- test/dummy/app/models/concerns/.keep
|
84
|
-
- test/dummy/app/twirp/views/pings/ping_template.pb.pbbuilder
|
85
86
|
- test/dummy/app/views/layouts/application.html.erb
|
86
87
|
- test/dummy/app/views/layouts/mailer.html.erb
|
87
88
|
- test/dummy/app/views/layouts/mailer.text.erb
|
89
|
+
- test/dummy/app/views/pings/ping_template.pb.pbbuilder
|
88
90
|
- test/dummy/bin/generate
|
89
91
|
- test/dummy/bin/rails
|
90
92
|
- test/dummy/bin/rake
|
@@ -162,15 +164,16 @@ test_files:
|
|
162
164
|
- test/dummy/app/controllers/concerns/.keep
|
163
165
|
- test/dummy/app/controllers/pings_controller.rb
|
164
166
|
- test/dummy/app/helpers/application_helper.rb
|
167
|
+
- test/dummy/app/helpers/random_helper.rb
|
165
168
|
- test/dummy/app/javascript/packs/application.js
|
166
169
|
- test/dummy/app/jobs/application_job.rb
|
167
170
|
- test/dummy/app/mailers/application_mailer.rb
|
168
171
|
- test/dummy/app/models/application_record.rb
|
169
172
|
- test/dummy/app/models/concerns/.keep
|
170
|
-
- test/dummy/app/twirp/views/pings/ping_template.pb.pbbuilder
|
171
173
|
- test/dummy/app/views/layouts/application.html.erb
|
172
174
|
- test/dummy/app/views/layouts/mailer.html.erb
|
173
175
|
- test/dummy/app/views/layouts/mailer.text.erb
|
176
|
+
- test/dummy/app/views/pings/ping_template.pb.pbbuilder
|
174
177
|
- test/dummy/bin/generate
|
175
178
|
- test/dummy/bin/rails
|
176
179
|
- test/dummy/bin/rake
|