stub_requests 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +27 -0
- data/gemfiles/webmock_2.3.gemfile.lock +1 -1
- data/gemfiles/webmock_3.5.gemfile.lock +1 -1
- data/gemfiles/webmock_develop.gemfile.lock +1 -1
- data/lib/stub_requests.rb +19 -14
- data/lib/stub_requests/api.rb +30 -16
- data/lib/stub_requests/argument_validation.rb +12 -12
- data/lib/stub_requests/endpoint.rb +12 -10
- data/lib/stub_requests/exceptions.rb +2 -6
- data/lib/stub_requests/metrics.rb +5 -4
- data/lib/stub_requests/metrics/{endpoint_stat.rb → endpoint.rb} +23 -22
- data/lib/stub_requests/metrics/registry.rb +25 -25
- data/lib/stub_requests/metrics/{stub_stat.rb → request.rb} +22 -13
- data/lib/stub_requests/observable.rb +62 -0
- data/lib/stub_requests/observable/registry.rb +152 -0
- data/lib/stub_requests/observable/subscription.rb +58 -0
- data/lib/stub_requests/property.rb +9 -3
- data/lib/stub_requests/property/validator.rb +4 -4
- data/lib/stub_requests/registration.rb +87 -0
- data/lib/stub_requests/registration/endpoint.rb +107 -0
- data/lib/stub_requests/registration/endpoints.rb +156 -0
- data/lib/stub_requests/registration/registry.rb +112 -0
- data/lib/stub_requests/registration/service.rb +85 -0
- data/lib/stub_requests/uri.rb +1 -1
- data/lib/stub_requests/version.rb +1 -1
- data/lib/tasks/changelog.rake +11 -2
- data/update_docs.sh +33 -0
- metadata +13 -8
- data/bin/update_docs.sh +0 -16
- data/lib/stub_requests/endpoint_registry.rb +0 -159
- data/lib/stub_requests/service.rb +0 -77
- data/lib/stub_requests/service_registry.rb +0 -104
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Abstraction over WebMock to reduce duplication
|
5
|
-
#
|
6
|
-
# @author Mikael Henriksson <mikael@zoolutions.se>
|
7
|
-
# @since 0.1.0
|
8
|
-
#
|
9
|
-
module StubRequests
|
10
|
-
#
|
11
|
-
# Class ServiceRegistry provides registration of services
|
12
|
-
#
|
13
|
-
# @author Mikael Henriksson <mikael@zoolutions.se>
|
14
|
-
#
|
15
|
-
class ServiceRegistry
|
16
|
-
include Singleton
|
17
|
-
include Enumerable
|
18
|
-
|
19
|
-
#
|
20
|
-
# @!attribute [rw] services
|
21
|
-
# @return [Concurrent::Map<Symbol, Service>] a map with services
|
22
|
-
attr_reader :services
|
23
|
-
|
24
|
-
def initialize
|
25
|
-
@services = Concurrent::Map.new
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Resets the map with registered services
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# @api private
|
33
|
-
def reset
|
34
|
-
services.clear
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# Required by Enumerable
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# @return [Concurrent::Map<Symbol, Service>] an map with services
|
42
|
-
#
|
43
|
-
# @yield used by Enumerable
|
44
|
-
#
|
45
|
-
def each(&block)
|
46
|
-
services.each(&block)
|
47
|
-
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# Registers a service in the registry
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# @param [Symbol] service_id a symbolic id of the service
|
54
|
-
# @param [String] service_uri a string with a base_uri to the service
|
55
|
-
#
|
56
|
-
# @return [Service] the service that was just registered
|
57
|
-
#
|
58
|
-
def register(service_id, service_uri)
|
59
|
-
if (service = find(service_id))
|
60
|
-
StubRequests.logger.warn("Service already registered #{service}")
|
61
|
-
raise ServiceHaveEndpoints, service if service.endpoints?
|
62
|
-
end
|
63
|
-
services[service_id] = Service.new(service_id, service_uri)
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# Removes a service from the registry
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# @param [Symbol] service_id the service_id to remove
|
71
|
-
#
|
72
|
-
# @raise [ServiceNotFound] when the service was not removed
|
73
|
-
#
|
74
|
-
def remove(service_id)
|
75
|
-
services.delete(service_id) || raise(ServiceNotFound, service_id)
|
76
|
-
end
|
77
|
-
|
78
|
-
#
|
79
|
-
# Fetches a service from the registry
|
80
|
-
#
|
81
|
-
#
|
82
|
-
# @param [Symbol] service_id id of the service to remove
|
83
|
-
#
|
84
|
-
# @return [Service] the found service
|
85
|
-
#
|
86
|
-
def find(service_id)
|
87
|
-
services[service_id]
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Fetches a service from the registry or raises {ServiceNotFound}
|
92
|
-
#
|
93
|
-
#
|
94
|
-
# @param [Symbol] service_id the id of a service
|
95
|
-
#
|
96
|
-
# @raise [ServiceNotFound] when an endpoint couldn't be found
|
97
|
-
#
|
98
|
-
# @return [Endpoint]
|
99
|
-
#
|
100
|
-
def find!(service_id)
|
101
|
-
find(service_id) || raise(ServiceNotFound, service_id)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|