stub_requests 0.1.2 → 0.1.3

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +1 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +27 -0
  5. data/gemfiles/webmock_2.3.gemfile.lock +1 -1
  6. data/gemfiles/webmock_3.5.gemfile.lock +1 -1
  7. data/gemfiles/webmock_develop.gemfile.lock +1 -1
  8. data/lib/stub_requests.rb +19 -14
  9. data/lib/stub_requests/api.rb +30 -16
  10. data/lib/stub_requests/argument_validation.rb +12 -12
  11. data/lib/stub_requests/endpoint.rb +12 -10
  12. data/lib/stub_requests/exceptions.rb +2 -6
  13. data/lib/stub_requests/metrics.rb +5 -4
  14. data/lib/stub_requests/metrics/{endpoint_stat.rb → endpoint.rb} +23 -22
  15. data/lib/stub_requests/metrics/registry.rb +25 -25
  16. data/lib/stub_requests/metrics/{stub_stat.rb → request.rb} +22 -13
  17. data/lib/stub_requests/observable.rb +62 -0
  18. data/lib/stub_requests/observable/registry.rb +152 -0
  19. data/lib/stub_requests/observable/subscription.rb +58 -0
  20. data/lib/stub_requests/property.rb +9 -3
  21. data/lib/stub_requests/property/validator.rb +4 -4
  22. data/lib/stub_requests/registration.rb +87 -0
  23. data/lib/stub_requests/registration/endpoint.rb +107 -0
  24. data/lib/stub_requests/registration/endpoints.rb +156 -0
  25. data/lib/stub_requests/registration/registry.rb +112 -0
  26. data/lib/stub_requests/registration/service.rb +85 -0
  27. data/lib/stub_requests/uri.rb +1 -1
  28. data/lib/stub_requests/version.rb +1 -1
  29. data/lib/tasks/changelog.rake +11 -2
  30. data/update_docs.sh +33 -0
  31. metadata +13 -8
  32. data/bin/update_docs.sh +0 -16
  33. data/lib/stub_requests/endpoint_registry.rb +0 -159
  34. data/lib/stub_requests/service.rb +0 -77
  35. 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