grpc_mock 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: fd11a8a9fe51756f230dd787fe6996643c68a7d4
4
- data.tar.gz: 2f3567d682c7d6e934ba7a8ca4c1f64cc98f6fc9
3
+ metadata.gz: 5a3a30164b826b389b7ab94f98d006695d0fbbe0
4
+ data.tar.gz: 52a58e8da81742811f8fc9f63e6f1b4eed6e5ed9
5
5
  SHA512:
6
- metadata.gz: 88dd0416c9169efe35bcb329eb6bb238458081adc70924f93e8d420b612f5aad88cc1aabd799ad010a672a990d03c584ba2aed3726c725963f0d3129ebf2e8ff
7
- data.tar.gz: a1660786ac25573a5fb282b29fd31966cc9eedf0ee73a242f3df224a5109ff9088b49e723869ac4b3cab1bf1f954d7a9df8a1b3d398c2e002f80012dad44f75e
6
+ metadata.gz: 054c34b5b45030d9671da3bb41952f77105f43f6554dbe4ab0a3812d90fa578c58e172020290ff3b5be07907cec4906abbcad4f3af14a5478f585d0db2d1df33
7
+ data.tar.gz: f733ca899fc9319e175cd953c9117c063a1759844f39faabfea697f2ba2eb39202cdd0c4f3cff327d06704c0e6a2ac2368a9b19f8a78b457c64b78ff2601fdc3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GrpcMock
1
+ # GrpcMock [![Build Status](https://travis-ci.org/ganmacs/grpc_mock.svg?branch=master)](https://travis-ci.org/ganmacs/grpc_mock)
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/grpc_mock`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
@@ -1,5 +1,5 @@
1
1
  require 'grpc_mock/version'
2
- require 'grpc_mock/configure'
2
+ require 'grpc_mock/configuration'
3
3
  require 'grpc_mock/adapter'
4
4
 
5
5
  module GrpcMock
@@ -25,7 +25,7 @@ module GrpcMock
25
25
  end
26
26
 
27
27
  def config
28
- @config ||= Configure.new
28
+ @config ||= Configuration.new
29
29
  end
30
30
  end
31
31
  end
@@ -1,5 +1,5 @@
1
1
  module GrpcMock
2
- class Configure
2
+ class Configuration
3
3
  attr_accessor :allow_net_connect
4
4
 
5
5
  def initialize
@@ -3,89 +3,78 @@ require 'grpc_mock/errors'
3
3
 
4
4
  module GrpcMock
5
5
  class GrpcStubAdapter
6
- # To make hook point for GRCP::ClientStub
6
+ # To make hook point for GRPC::ClientStub
7
7
  # https://github.com/grpc/grpc/blob/bec3b5ada2c5e5d782dff0b7b5018df646b65cb0/src/ruby/lib/grpc/generic/service.rb#L150-L186
8
- ADAPTER_CLASS = Class.new(GRPC::ClientStub) do
9
- alias_method :original_request_response, :request_response
10
- alias_method :original_client_streamer, :client_streamer
11
- alias_method :original_server_streamer, :server_streamer
12
- alias_method :original_bidi_streamer, :bidi_streamer
13
- end
14
- GRPC.send(:remove_const, :ClientStub)
15
- GRPC.send(:const_set, :ClientStub, ADAPTER_CLASS)
8
+ class AdapterClass < GRPC::ClientStub
9
+ def request_response(method, *args)
10
+ unless GrpcMock::GrpcStubAdapter.enabled?
11
+ return super
12
+ end
16
13
 
17
- HOOKED_CLASS = Module.new do
18
- def request_response(method, req, marshal, unmarshal, **opt)
19
14
  if GrpcMock.config.allow_net_connect
20
- original_request_response(method, req, marshal, unmarshal, **opt)
15
+ super
21
16
  else
22
17
  raise NetConnectNotAllowedError, method
23
18
  end
24
19
  end
25
20
 
26
- def client_streamer(method, requests, marshal, unmarshal, **opt)
21
+ def client_streamer(method, *args)
22
+ unless GrpcMock::GrpcStubAdapter.enabled?
23
+ return super
24
+ end
25
+
27
26
  if GrpcMock.config.allow_net_connect
28
- original_client_streamer(method, requests, marshal, unmarshal, **opt)
27
+ super
29
28
  else
30
29
  raise NetConnectNotAllowedError, method
31
30
  end
32
31
  end
33
32
 
34
- def server_streamer(method, req, marshal, unmarshal, **opt)
33
+ def server_streamer(method, *args)
34
+ unless GrpcMock::GrpcStubAdapter.enabled?
35
+ return super
36
+ end
37
+
35
38
  if GrpcMock.config.allow_net_connect
36
- original_server_streamer(method, req, marshal, unmarshal, **opt)
39
+ super
37
40
  else
38
41
  raise NetConnectNotAllowedError, method
39
42
  end
40
43
  end
41
44
 
42
- def bidi_streamer(method, requests, marshal, unmarshal, **opt)
45
+ def bidi_streamer(method, *args)
46
+ unless GrpcMock::GrpcStubAdapter.enabled?
47
+ return super
48
+ end
49
+
43
50
  if GrpcMock.config.allow_net_connect
44
- original_bidi_streamer(method, requests, marshal, unmarshal, **opt)
51
+ super
45
52
  else
46
53
  raise NetConnectNotAllowedError, method
47
54
  end
48
55
  end
49
56
  end
57
+ GRPC.send(:remove_const, :ClientStub)
58
+ GRPC.send(:const_set, :ClientStub, AdapterClass)
50
59
 
51
- # This class is only used for disabling grpc_stub_adapter hook
52
- THROUGHT_CLASS = Module.new do
53
- def request_response(method, req, marshal, unmarshal, **opt)
54
- original_request_response(method, req, marshal, unmarshal, **opt)
55
- end
56
-
57
- def client_streamer(method, requests, marshal, unmarshal, **opt)
58
- original_client_streamer(method, requests, marshal, unmarshal, **opt)
59
- end
60
+ def self.disable!
61
+ @enabled = false
62
+ end
60
63
 
61
- def server_streamer(method, req, marshal, unmarshal, **opt)
62
- original_server_streamer(method, req, marshal, unmarshal, **opt)
63
- end
64
+ def self.enable!
65
+ @enabled = true
66
+ end
64
67
 
65
- def bidi_streamer(method, requests, marshal, unmarshal, **opt)
66
- original_bidi_streamer(method, requests, marshal, unmarshal, **opt)
67
- end
68
+ def self.enabled?
69
+ @enabled
68
70
  end
69
71
 
70
72
  def enable!
71
- clean_up
72
- ADAPTER_CLASS.prepend(HOOKED_CLASS)
73
+ GrpcMock::GrpcStubAdapter.enable!
73
74
  end
74
75
 
75
76
  def disable!
76
- clean_up
77
- ADAPTER_CLASS.prepend(THROUGHT_CLASS)
78
- end
79
-
80
- private
81
-
82
- def clean_up
83
- ADAPTER_CLASS.class_eval do
84
- undef_method(:request_response)
85
- undef_method(:client_streamer)
86
- undef_method(:server_streamer)
87
- undef_method(:bidi_streamer)
88
- end
77
+ GrpcMock::GrpcStubAdapter.disable!
89
78
  end
90
79
  end
91
80
  end
@@ -1,3 +1,3 @@
1
1
  module GrpcMock
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ganmacs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -129,7 +129,7 @@ files:
129
129
  - grpc_mock.gemspec
130
130
  - lib/grpc_mock.rb
131
131
  - lib/grpc_mock/adapter.rb
132
- - lib/grpc_mock/configure.rb
132
+ - lib/grpc_mock/configuration.rb
133
133
  - lib/grpc_mock/errors.rb
134
134
  - lib/grpc_mock/grpc_stub_adapter.rb
135
135
  - lib/grpc_mock/rspec.rb