proto_pharm 0.6.0 → 0.7.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/.github/workflows/rspec.yml +1 -1
- data/CHANGELOG.md +12 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +38 -1
- data/README.md +20 -1
- data/lib/proto_pharm.rb +11 -4
- data/lib/proto_pharm/action_stub.rb +7 -3
- data/lib/proto_pharm/api.rb +6 -6
- data/lib/proto_pharm/configuration.rb +8 -4
- data/lib/proto_pharm/grpc_stub_adapter/mock_stub.rb +25 -5
- data/lib/proto_pharm/metadata_serializers/base.rb +13 -0
- data/lib/proto_pharm/metadata_serializers/freshly.rb +24 -0
- data/lib/proto_pharm/metadata_serializers/gruf.rb +37 -0
- data/lib/proto_pharm/request_stub.rb +10 -2
- data/lib/proto_pharm/response.rb +9 -3
- data/lib/proto_pharm/stub_components/failure_response.rb +7 -5
- data/lib/proto_pharm/version.rb +1 -1
- data/proto_pharm.gemspec +2 -0
- metadata +33 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '085284c66deb0cdd0054f9b2663d9e1ef0c1a71384cc9af964f7ff02382d187d'
|
|
4
|
+
data.tar.gz: b86a47f713e24e281c28378f89a6efe06aa5b971787d3a1b842b32d7e2954cc7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbf7f332455eb884bfc2fe52c1bdf7488b7d64aff8f5f54b972aa09b21e340cc64e47a7e55fa27d7da37d94dfe3b6fcbea02f8c648f4ad02bd5a1f2d978c3253
|
|
7
|
+
data.tar.gz: 753a2290f4529efae044337f00431cce790f2b831256a323e92c157cd289a04d71f04a5d063d7b2f94fd0ae1883f93abca2899a61e799ec16456f1096d23c60c
|
data/.github/workflows/rspec.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Upcoming
|
|
4
|
+
|
|
5
|
+
## 0.7.0
|
|
6
|
+
*Release Date: 2021-02-19*
|
|
7
|
+
|
|
8
|
+
### Additions
|
|
9
|
+
- Add configurable metadata serializer ([#6](https://github.com/Freshly/proto_pharm/pull/6))
|
|
10
|
+
- Add metadata serializer for Gruf ([#7](https://github.com/Freshly/proto_pharm/pull/7))
|
|
11
|
+
- Stub responses using a block ([#8](https://github.com/Freshly/proto_pharm/pull/8))
|
|
12
|
+
- Net connect method cleanup ([#9](https://github.com/Freshly/proto_pharm/pull/9))
|
|
13
|
+
|
|
14
|
+
## 0.6.0
|
|
4
15
|
*Release Date: 2020-12-07*
|
|
5
16
|
|
|
6
17
|
- Rename gem to `proto_pharm`
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
proto_pharm (0.
|
|
4
|
+
proto_pharm (0.7.0)
|
|
5
5
|
activesupport (>= 5.2.0)
|
|
6
|
+
directive
|
|
6
7
|
grpc (>= 1.12.0, < 2)
|
|
7
8
|
|
|
8
9
|
GEM
|
|
9
10
|
remote: https://rubygems.org/
|
|
10
11
|
specs:
|
|
12
|
+
activemodel (6.0.3.4)
|
|
13
|
+
activesupport (= 6.0.3.4)
|
|
11
14
|
activesupport (6.0.3.4)
|
|
12
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
16
|
i18n (>= 0.7, < 2)
|
|
14
17
|
minitest (~> 5.1)
|
|
15
18
|
tzinfo (~> 1.1)
|
|
16
19
|
zeitwerk (~> 2.2, >= 2.2.2)
|
|
20
|
+
around_the_world (0.25.4)
|
|
21
|
+
activesupport (>= 5.2.1)
|
|
17
22
|
ast (2.4.1)
|
|
18
23
|
byebug (11.1.1)
|
|
19
24
|
coderay (1.1.2)
|
|
20
25
|
concurrent-ruby (1.1.7)
|
|
21
26
|
diff-lcs (1.4.4)
|
|
27
|
+
directive (0.25.4)
|
|
28
|
+
activesupport (>= 5.2.1)
|
|
29
|
+
spicerack (= 0.25.4)
|
|
22
30
|
faker (2.14.0)
|
|
23
31
|
i18n (>= 1.6, < 2)
|
|
24
32
|
google-protobuf (3.14.0)
|
|
@@ -28,6 +36,12 @@ GEM
|
|
|
28
36
|
google-protobuf (~> 3.13)
|
|
29
37
|
googleapis-common-protos-types (~> 1.0)
|
|
30
38
|
grpc-tools (1.32.0)
|
|
39
|
+
gruf (2.8.1)
|
|
40
|
+
activesupport (> 4)
|
|
41
|
+
concurrent-ruby (> 1)
|
|
42
|
+
grpc (~> 1.10)
|
|
43
|
+
grpc-tools (~> 1.10)
|
|
44
|
+
slop (~> 4.6)
|
|
31
45
|
i18n (1.8.5)
|
|
32
46
|
concurrent-ruby (~> 1.0)
|
|
33
47
|
method_source (0.9.2)
|
|
@@ -44,6 +58,11 @@ GEM
|
|
|
44
58
|
rack (2.2.3)
|
|
45
59
|
rainbow (3.0.0)
|
|
46
60
|
rake (13.0.1)
|
|
61
|
+
redis (4.2.5)
|
|
62
|
+
redis_hash (0.25.4)
|
|
63
|
+
activesupport (>= 5.2.1)
|
|
64
|
+
redis (>= 3.0)
|
|
65
|
+
tablesalt (= 0.25.4)
|
|
47
66
|
regexp_parser (1.8.2)
|
|
48
67
|
rexml (3.2.4)
|
|
49
68
|
rspec (3.9.0)
|
|
@@ -83,11 +102,27 @@ GEM
|
|
|
83
102
|
rubocop-rspec (1.43.2)
|
|
84
103
|
rubocop (~> 0.87)
|
|
85
104
|
ruby-progressbar (1.10.1)
|
|
105
|
+
short_circu_it (0.25.4)
|
|
106
|
+
activesupport (>= 5.2.1)
|
|
107
|
+
around_the_world (= 0.25.4)
|
|
108
|
+
slop (4.8.2)
|
|
109
|
+
spicerack (0.25.4)
|
|
110
|
+
around_the_world (= 0.25.4)
|
|
111
|
+
redis_hash (= 0.25.4)
|
|
112
|
+
short_circu_it (= 0.25.4)
|
|
113
|
+
tablesalt (= 0.25.4)
|
|
114
|
+
technologic (= 0.25.4)
|
|
86
115
|
spicerack-styleguide (0.25.2)
|
|
87
116
|
rubocop (~> 0.92.0)
|
|
88
117
|
rubocop-performance (~> 1.8.0)
|
|
89
118
|
rubocop-rails (~> 2.8.0)
|
|
90
119
|
rubocop-rspec (~> 1.43.0)
|
|
120
|
+
tablesalt (0.25.4)
|
|
121
|
+
activemodel (>= 5.2.1)
|
|
122
|
+
activesupport (>= 5.2.1)
|
|
123
|
+
technologic (0.25.4)
|
|
124
|
+
activesupport (>= 5.2.1)
|
|
125
|
+
short_circu_it (= 0.25.4)
|
|
91
126
|
thread_safe (0.3.6)
|
|
92
127
|
tzinfo (1.2.8)
|
|
93
128
|
thread_safe (~> 0.1)
|
|
@@ -100,7 +135,9 @@ PLATFORMS
|
|
|
100
135
|
DEPENDENCIES
|
|
101
136
|
bundler
|
|
102
137
|
faker
|
|
138
|
+
grpc
|
|
103
139
|
grpc-tools
|
|
140
|
+
gruf
|
|
104
141
|
proto_pharm!
|
|
105
142
|
pry-byebug
|
|
106
143
|
rake (>= 12.3.3)
|
data/README.md
CHANGED
|
@@ -60,6 +60,16 @@ client.hello(Hello::HelloRequest.new(msg: 'Hello?')) # => Sent to network
|
|
|
60
60
|
client.hello(Hello::HelloRequest.new(msg: 'Hola?')) # => <Hello::HelloResponse: msg: "Bienvenidos!">
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
Or, stub the response with a block to perform some additional business logic:
|
|
64
|
+
_(Note - the `allow_grpc_service` syntax currently does not support block-stubbing)_
|
|
65
|
+
```ruby
|
|
66
|
+
stub_grpc_action(Hello::Hello::Service, :Hello).to_return do |request|
|
|
67
|
+
{ msg: request.msg.reverse }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
client.hello(Hello::HelloRequest.new(msg: 'Hello?')) # => <Hello::HelloResponse: msg: "?olleH">
|
|
71
|
+
```
|
|
72
|
+
|
|
63
73
|
Stub a failure response:
|
|
64
74
|
```ruby
|
|
65
75
|
allow_grpc_service(Hello::Hello)
|
|
@@ -150,7 +160,16 @@ client.hello(Hello::HelloRequest.new(msg: 'hi')) # => Hello::HelloResponse.ne
|
|
|
150
160
|
|
|
151
161
|
```
|
|
152
162
|
|
|
153
|
-
###
|
|
163
|
+
### Stubbing with a block
|
|
164
|
+
```ruby
|
|
165
|
+
ProtoPharm.stub_grpc_action(Hello::Hello::Service, :Hello).to_return do |request|
|
|
166
|
+
{ msg: request.msg.reverse }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
client.hello(Hello::HelloRequest.new(msg: 'Hello?')) # => <Hello::HelloResponse: msg: "?olleH">
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### You can use either proto objects or hash for stubbing requests
|
|
154
173
|
|
|
155
174
|
```ruby
|
|
156
175
|
ProtoPharm.stub_grpc_action(Hello::Hello::Service, :Hello).with(Hello::HelloRequest.new(msg: 'hi')).to_return(msg: 'test')
|
data/lib/proto_pharm.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "active_support/core_ext/module"
|
|
4
|
+
require "active_support/core_ext/object/blank"
|
|
5
|
+
|
|
6
|
+
require "directive"
|
|
4
7
|
require "grpc"
|
|
5
8
|
|
|
6
9
|
require_relative "proto_pharm/version"
|
|
@@ -13,12 +16,20 @@ require_relative "proto_pharm/adapter"
|
|
|
13
16
|
require_relative "proto_pharm/grpc_stub_adapter"
|
|
14
17
|
require_relative "proto_pharm/grpc_stub_adapter/mock_stub"
|
|
15
18
|
|
|
19
|
+
require_relative "proto_pharm/metadata_serializers/base"
|
|
20
|
+
require_relative "proto_pharm/metadata_serializers/gruf"
|
|
21
|
+
require_relative "proto_pharm/request_stub"
|
|
22
|
+
require_relative "proto_pharm/action_stub"
|
|
23
|
+
require_relative "proto_pharm/matchers/request_including_matcher"
|
|
16
24
|
require_relative "proto_pharm/stub_registry"
|
|
17
25
|
require_relative "proto_pharm/api"
|
|
18
26
|
|
|
19
27
|
module ProtoPharm
|
|
20
28
|
extend ProtoPharm::Api
|
|
21
29
|
|
|
30
|
+
include Directive::ConfigDelegation
|
|
31
|
+
delegates_to_configuration
|
|
32
|
+
|
|
22
33
|
class << self
|
|
23
34
|
delegate :enable!, :disable!, :enabled?, to: :adapter
|
|
24
35
|
|
|
@@ -33,10 +44,6 @@ module ProtoPharm
|
|
|
33
44
|
def adapter
|
|
34
45
|
@adapter ||= Adapter.new
|
|
35
46
|
end
|
|
36
|
-
|
|
37
|
-
def config
|
|
38
|
-
@config ||= Configuration.new
|
|
39
|
-
end
|
|
40
47
|
end
|
|
41
48
|
|
|
42
49
|
# Hook into GRPC::ClientStub
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "active_support/core_ext/object/blank"
|
|
4
|
-
|
|
5
3
|
module ProtoPharm
|
|
6
4
|
class ActionStub < RequestStub
|
|
7
5
|
include Introspection
|
|
@@ -26,7 +24,13 @@ module ProtoPharm
|
|
|
26
24
|
|
|
27
25
|
# @param proto [Object] response proto object
|
|
28
26
|
# @param request_kwargs [Hash] parameters to respond with
|
|
29
|
-
def to_return(proto = nil, **request_kwargs)
|
|
27
|
+
def to_return(proto = nil, **request_kwargs, &block)
|
|
28
|
+
if block_given?
|
|
29
|
+
raise ArgumentError, "Cannot stub with static response if stubbing with a block" if proto.present? || request_kwargs.present?
|
|
30
|
+
|
|
31
|
+
return super(&block)
|
|
32
|
+
end
|
|
33
|
+
|
|
30
34
|
super(endpoint.normalize_response_proto(proto, **request_kwargs))
|
|
31
35
|
end
|
|
32
36
|
|
data/lib/proto_pharm/api.rb
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "proto_pharm/request_stub"
|
|
4
|
-
require "proto_pharm/action_stub"
|
|
5
|
-
require "proto_pharm/matchers/request_including_matcher"
|
|
6
|
-
|
|
7
3
|
module ProtoPharm
|
|
8
4
|
module Api
|
|
9
5
|
# @param path [String]
|
|
@@ -21,11 +17,15 @@ module ProtoPharm
|
|
|
21
17
|
end
|
|
22
18
|
|
|
23
19
|
def disable_net_connect!
|
|
24
|
-
|
|
20
|
+
GrpcStubAdapter::MockStub.disable_net_connect!
|
|
25
21
|
end
|
|
26
22
|
|
|
27
23
|
def allow_net_connect!
|
|
28
|
-
|
|
24
|
+
GrpcStubAdapter::MockStub.allow_net_connect!
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def allow_net_connect?
|
|
28
|
+
GrpcStubAdapter::MockStub.allow_net_connect?
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "directive"
|
|
4
|
+
require_relative "metadata_serializers/base"
|
|
5
|
+
require_relative "metadata_serializers/gruf"
|
|
6
|
+
|
|
3
7
|
module ProtoPharm
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
module Configuration
|
|
9
|
+
extend Directive
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
configuration_options do
|
|
12
|
+
option :metadata_serializer, default: MetadataSerializers::Base
|
|
9
13
|
end
|
|
10
14
|
end
|
|
11
15
|
end
|
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
module ProtoPharm
|
|
4
4
|
class GrpcStubAdapter
|
|
5
5
|
module MockStub
|
|
6
|
+
class << self
|
|
7
|
+
def disable_net_connect!
|
|
8
|
+
@allow_net_connect = false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def allow_net_connect!
|
|
12
|
+
@allow_net_connect = true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def allow_net_connect?
|
|
16
|
+
@allow_net_connect || false
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
6
20
|
def request_response(method, request, *args, return_op: false, **opts)
|
|
7
21
|
return super unless ProtoPharm.enabled?
|
|
8
22
|
|
|
@@ -11,11 +25,11 @@ module ProtoPharm
|
|
|
11
25
|
if request_stub
|
|
12
26
|
operation = OperationStub.new(metadata: opts[:metadata]) do
|
|
13
27
|
request_stub.received!(request)
|
|
14
|
-
request_stub.response.evaluate
|
|
28
|
+
request_stub.response.evaluate(request)
|
|
15
29
|
end
|
|
16
30
|
|
|
17
31
|
return_op ? operation : operation.execute
|
|
18
|
-
elsif
|
|
32
|
+
elsif _allow_net_connect?
|
|
19
33
|
super
|
|
20
34
|
else
|
|
21
35
|
raise NetConnectNotAllowedError, method
|
|
@@ -32,7 +46,7 @@ module ProtoPharm
|
|
|
32
46
|
if request_stub
|
|
33
47
|
request_stub.received!(requests)
|
|
34
48
|
request_stub.response.evaluate
|
|
35
|
-
elsif
|
|
49
|
+
elsif _allow_net_connect?
|
|
36
50
|
super
|
|
37
51
|
else
|
|
38
52
|
raise NetConnectNotAllowedError, method
|
|
@@ -47,7 +61,7 @@ module ProtoPharm
|
|
|
47
61
|
if request_stub
|
|
48
62
|
request_stub.received!(request)
|
|
49
63
|
request_stub.response.evaluate
|
|
50
|
-
elsif
|
|
64
|
+
elsif _allow_net_connect?
|
|
51
65
|
super
|
|
52
66
|
else
|
|
53
67
|
raise NetConnectNotAllowedError, method
|
|
@@ -63,12 +77,18 @@ module ProtoPharm
|
|
|
63
77
|
if request_stub
|
|
64
78
|
request_stub.received!(requests)
|
|
65
79
|
request_stub.response.evaluate
|
|
66
|
-
elsif
|
|
80
|
+
elsif _allow_net_connect?
|
|
67
81
|
super
|
|
68
82
|
else
|
|
69
83
|
raise NetConnectNotAllowedError, method
|
|
70
84
|
end
|
|
71
85
|
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def _allow_net_connect?
|
|
90
|
+
MockStub.allow_net_connect?
|
|
91
|
+
end
|
|
72
92
|
end
|
|
73
93
|
end
|
|
74
94
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ProtoPharm
|
|
4
|
+
module MetadataSerializers
|
|
5
|
+
module Freshly
|
|
6
|
+
class << self
|
|
7
|
+
def serialize(code:, app_code: nil, **kwargs)
|
|
8
|
+
metadata = kwargs.fetch(:metadata, {})
|
|
9
|
+
|
|
10
|
+
{
|
|
11
|
+
metadata: metadata,
|
|
12
|
+
}.tap do |hash|
|
|
13
|
+
if ::Gruf.append_server_errors_to_trailing_metadata
|
|
14
|
+
enc_metadata = Labyrinth::GrufComponents::ErrorSerializer.encoded_metadata_hash(metadata)
|
|
15
|
+
|
|
16
|
+
e = ::Gruf::Error.new(code: code, app_code: app_code, metadata: enc_metadata)
|
|
17
|
+
hash[::Gruf.error_metadata_key.to_sym] = e.serialize
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Serializes metadata for an application's Gruf configuration.
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# Configuration.configure { |c| c.metadata_serializer = ProtoPharm::MetadataSerializers::Gruf }
|
|
7
|
+
#
|
|
8
|
+
# allow_grpc_service(AService)
|
|
9
|
+
# .to receive_rpc(:your_endpoint)
|
|
10
|
+
# .and_fail_with(
|
|
11
|
+
# code: :invalid_argument,
|
|
12
|
+
# app_code: :cant_let_you_do_that_star_fox
|
|
13
|
+
# metadata: { some: :meta }
|
|
14
|
+
# )
|
|
15
|
+
#
|
|
16
|
+
# begin
|
|
17
|
+
# Service.your_endpoint
|
|
18
|
+
# rescue Gruf::Client::Error::InvalidArgument => e
|
|
19
|
+
# e.error
|
|
20
|
+
module ProtoPharm
|
|
21
|
+
module MetadataSerializers
|
|
22
|
+
module Gruf
|
|
23
|
+
class << self
|
|
24
|
+
def serialize(code:, app_code: nil, **metadata)
|
|
25
|
+
{
|
|
26
|
+
**metadata.fetch(:metadata, {}),
|
|
27
|
+
}.tap do |hash|
|
|
28
|
+
if ::Gruf.append_server_errors_to_trailing_metadata
|
|
29
|
+
e = ::Gruf::Error.new(code: code, app_code: app_code, **metadata)
|
|
30
|
+
hash[::Gruf.error_metadata_key.to_sym] = e.serialize
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -23,9 +23,17 @@ module ProtoPharm
|
|
|
23
23
|
self
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def to_return(*values)
|
|
27
|
-
|
|
26
|
+
def to_return(*values, &block)
|
|
27
|
+
if block_given?
|
|
28
|
+
raise ArgumentError, "Cannot stub with static response if stubbing with a block" if values.any?
|
|
29
|
+
|
|
30
|
+
responses = [ Response::Value.new(block) ]
|
|
31
|
+
else
|
|
32
|
+
responses = [*values].flatten.map { |v| Response::Value.new(v) }
|
|
33
|
+
end
|
|
34
|
+
|
|
28
35
|
@response_sequence << ProtoPharm::ResponsesSequence.new(responses)
|
|
36
|
+
|
|
29
37
|
self
|
|
30
38
|
end
|
|
31
39
|
|
data/lib/proto_pharm/response.rb
CHANGED
|
@@ -18,18 +18,24 @@ module ProtoPharm
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def evaluate
|
|
21
|
+
def evaluate(_request = nil)
|
|
22
22
|
raise @exception.dup
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
class Value
|
|
27
|
+
attr_reader :value
|
|
28
|
+
|
|
27
29
|
def initialize(value)
|
|
28
30
|
@value = value
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
def evaluate
|
|
32
|
-
|
|
33
|
+
def evaluate(request = nil)
|
|
34
|
+
if value.respond_to?(:call)
|
|
35
|
+
value.call(request)
|
|
36
|
+
else
|
|
37
|
+
value.dup
|
|
38
|
+
end
|
|
33
39
|
end
|
|
34
40
|
end
|
|
35
41
|
end
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "active_support/core_ext/object/blank"
|
|
4
|
-
|
|
5
3
|
module ProtoPharm
|
|
6
4
|
module StubComponents
|
|
7
5
|
module FailureResponse
|
|
8
6
|
# @param code [String, Symbol] A gRPC failure code, such as not_found or invalid_argument. Default: :invalid_argument
|
|
9
7
|
# @param message [String] A message to pass back with the exception
|
|
10
|
-
# @param metadata [Hash] A hash of metadata to be passed back with the exception
|
|
11
|
-
def to_fail_with(code = :invalid_argument, message = "unknown cause", metadata
|
|
12
|
-
to_raise(exception_class(code).new(message, metadata))
|
|
8
|
+
# @param metadata [Hash] A hash of metadata to be passed back with the exception. See {ProtoPharm::MetadataSerializers::Base.serialize}.
|
|
9
|
+
def to_fail_with(code = :invalid_argument, message = "unknown cause", **metadata)
|
|
10
|
+
to_raise(exception_class(code).new(message, metadata_serializer.serialize(code: code, message: message, **metadata)))
|
|
13
11
|
end
|
|
14
12
|
|
|
15
13
|
def to_fail
|
|
@@ -18,6 +16,10 @@ module ProtoPharm
|
|
|
18
16
|
|
|
19
17
|
private
|
|
20
18
|
|
|
19
|
+
def metadata_serializer
|
|
20
|
+
Configuration.config.metadata_serializer
|
|
21
|
+
end
|
|
22
|
+
|
|
21
23
|
def exception_class(code)
|
|
22
24
|
class_name = code.to_s.camelize
|
|
23
25
|
|
data/lib/proto_pharm/version.rb
CHANGED
data/proto_pharm.gemspec
CHANGED
|
@@ -24,10 +24,12 @@ Gem::Specification.new do |spec|
|
|
|
24
24
|
spec.require_paths = ["lib"]
|
|
25
25
|
|
|
26
26
|
spec.add_dependency "activesupport", ">= 5.2.0"
|
|
27
|
+
spec.add_dependency "directive"
|
|
27
28
|
spec.add_dependency "grpc", ">= 1.12.0", "< 2"
|
|
28
29
|
|
|
29
30
|
spec.add_development_dependency "bundler"
|
|
30
31
|
spec.add_development_dependency "faker"
|
|
32
|
+
spec.add_development_dependency "gruf"
|
|
31
33
|
spec.add_development_dependency "grpc-tools"
|
|
32
34
|
spec.add_development_dependency "pry-byebug"
|
|
33
35
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: proto_pharm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yuta Iwama
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2021-02-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -25,6 +25,20 @@ dependencies:
|
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
27
|
version: 5.2.0
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: directive
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :runtime
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
28
42
|
- !ruby/object:Gem::Dependency
|
|
29
43
|
name: grpc
|
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -73,6 +87,20 @@ dependencies:
|
|
|
73
87
|
- - ">="
|
|
74
88
|
- !ruby/object:Gem::Version
|
|
75
89
|
version: '0'
|
|
90
|
+
- !ruby/object:Gem::Dependency
|
|
91
|
+
name: gruf
|
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
type: :development
|
|
98
|
+
prerelease: false
|
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
76
104
|
- !ruby/object:Gem::Dependency
|
|
77
105
|
name: grpc-tools
|
|
78
106
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -207,6 +235,9 @@ files:
|
|
|
207
235
|
- lib/proto_pharm/introspection/service_resolver.rb
|
|
208
236
|
- lib/proto_pharm/matchers/hash_argument_matcher.rb
|
|
209
237
|
- lib/proto_pharm/matchers/request_including_matcher.rb
|
|
238
|
+
- lib/proto_pharm/metadata_serializers/base.rb
|
|
239
|
+
- lib/proto_pharm/metadata_serializers/freshly.rb
|
|
240
|
+
- lib/proto_pharm/metadata_serializers/gruf.rb
|
|
210
241
|
- lib/proto_pharm/operation_stub.rb
|
|
211
242
|
- lib/proto_pharm/request_pattern.rb
|
|
212
243
|
- lib/proto_pharm/request_stub.rb
|