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
@@ -0,0 +1,85 @@
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
+ # Module Registration provides registration of stubbed endpoints and services
12
+ #
13
+ # @author Mikael Henriksson <mikael@zoolutions.se>
14
+ # @since 0.1.3
15
+ #
16
+ module Registration
17
+ #
18
+ # Class Service provides details for a registered service
19
+ #
20
+ # @author Mikael Henriksson <mikael@zoolutions.se>
21
+ #
22
+ class Service
23
+ include Comparable
24
+ include Property
25
+
26
+ # @!attribute [rw] id
27
+ # @return [Symbol] the id of the service
28
+ property :id, type: Symbol
29
+
30
+ # @!attribute [rw] uri
31
+ # @return [String] the base uri to the service
32
+ property :uri, type: String
33
+
34
+ # @!attribute [rw] endpoints
35
+ # @return [Endpoints] a list with defined endpoints
36
+ attr_reader :endpoints
37
+
38
+ #
39
+ # Initializes a new instance of a Service
40
+ #
41
+ # @param [Symbol] service_id the id of this service
42
+ # @param [String] service_uri the base uri to reach the service
43
+ #
44
+ def initialize(service_id, service_uri)
45
+ self.id = service_id
46
+ self.uri = service_uri
47
+ @endpoints = Endpoints.new
48
+ end
49
+
50
+ #
51
+ # Check if the endpoint registry has endpoints
52
+ #
53
+ # @return [true,false]
54
+ #
55
+ def endpoints?
56
+ endpoints.any?
57
+ end
58
+
59
+ #
60
+ # Returns a nicely formatted string with this service
61
+ #
62
+ # @return [String]
63
+ #
64
+ def to_s
65
+ [
66
+ +"#<#{self.class}",
67
+ +" id=#{id}",
68
+ +" uri=#{uri}",
69
+ +" endpoints=#{endpoints.endpoints_string}",
70
+ +">",
71
+ ].join("")
72
+ end
73
+
74
+ def <=>(other)
75
+ id <=> other.id
76
+ end
77
+
78
+ def hash
79
+ [id, self.class].hash
80
+ end
81
+
82
+ alias eql? ==
83
+ end
84
+ end
85
+ end
@@ -24,7 +24,7 @@ module StubRequests
24
24
  # @return [Array<Service, Endpoint, String] the service, endpoint and full URI
25
25
  #
26
26
  def self.for_service_endpoint(service_id, endpoint_id, replacements)
27
- service = ServiceRegistry.instance.find!(service_id)
27
+ service = Registration::Registry.instance.find!(service_id)
28
28
  endpoint = service.endpoints.find!(endpoint_id)
29
29
  uri = URI::Builder.build(service.uri, endpoint.uri_template, replacements)
30
30
 
@@ -9,5 +9,5 @@
9
9
  module StubRequests
10
10
  #
11
11
  # @return [String] a version string
12
- VERSION = "0.1.2"
12
+ VERSION = "0.1.3"
13
13
  end
@@ -3,7 +3,7 @@
3
3
  desc "Generate a Changelog"
4
4
  task :changelog do
5
5
  # rubocop:disable Style/MutableConstant
6
- CHANGELOG_COMMAND ||= %w[
6
+ CHANGELOG_CMD ||= %w[
7
7
  github_changelog_generator
8
8
  -u
9
9
  mhenrixon
@@ -12,7 +12,16 @@ task :changelog do
12
12
  --no-verbose
13
13
  --token
14
14
  ]
15
+ CHECKOUT_CHANGELOG_CMD ||= "git checkout -B update-changelog"
16
+ COMMIT_CHANGELOG_CMD ||= "git add --all"
17
+ COMMIT_CHANGELOG_CMD ||= "git commit -a -m 'Update changelog'"
18
+ GIT_PUSH_CMD ||= "git push -u origin update-changelog"
19
+ OPEN_PR_CMD ||= "hub pull-request -b master -m 'Update Changelog' -a mhenrixon -l changelog"
15
20
  # rubocop:enable Style/MutableConstant
16
21
 
17
- sh(*CHANGELOG_COMMAND.push(ENV["CHANGELOG_GITHUB_TOKEN"]))
22
+ sh(*CHANGELOG_CMD.push(ENV["CHANGELOG_GITHUB_TOKEN"]))
23
+ sh(CHECKOUT_CHANGELOG_CMD)
24
+ sh(COMMIT_CHANGELOG_CMD)
25
+ sh(GIT_PUSH_CMD)
26
+ sh(OPEN_PR_CMD)
18
27
  end
data/update_docs.sh ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env bash
2
+
3
+ git checkout master
4
+ git fetch
5
+ stash_created=0
6
+
7
+ if [[ "$(git diff --stat)" != "" ]]; then
8
+ stash_created=1
9
+ git stash push -u -a -m "Before updating docs"
10
+ fi;
11
+
12
+ git reset --hard origin/master
13
+
14
+ rake yard
15
+
16
+ git checkout gh-pages
17
+
18
+ echo "Cleaning up current documentation"
19
+ find . ! -path '*/.git*' ! -path '*/doc*' ! -path '*/update_docs.sh*' ! -path '*/_config.yml*' ! -path '*/_index.html*' ! -path '.' | xargs rm -rf
20
+
21
+ echo "Copying new documentation"
22
+ mv doc/* ./
23
+
24
+ echo "Sending new documentation to github"
25
+ git add --all
26
+ git commit -a -m 'Update documentation'
27
+ git push
28
+
29
+ if [[ $stash_created == 1 ]]; then
30
+ git stash pop
31
+ fi;
32
+
33
+ git checkout master
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stub_requests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-03 00:00:00.000000000 Z
11
+ date: 2019-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -370,7 +370,6 @@ files:
370
370
  - _config.yml
371
371
  - bin/console
372
372
  - bin/setup
373
- - bin/update_docs.sh
374
373
  - gemfiles/.bundle/config
375
374
  - gemfiles/webmock_2.3.gemfile
376
375
  - gemfiles/webmock_2.3.gemfile.lock
@@ -392,17 +391,22 @@ files:
392
391
  - lib/stub_requests/core_ext/module/redefine_method.rb
393
392
  - lib/stub_requests/core_ext/object/blank.rb
394
393
  - lib/stub_requests/endpoint.rb
395
- - lib/stub_requests/endpoint_registry.rb
396
394
  - lib/stub_requests/exceptions.rb
397
395
  - lib/stub_requests/hash_util.rb
398
396
  - lib/stub_requests/metrics.rb
399
- - lib/stub_requests/metrics/endpoint_stat.rb
397
+ - lib/stub_requests/metrics/endpoint.rb
400
398
  - lib/stub_requests/metrics/registry.rb
401
- - lib/stub_requests/metrics/stub_stat.rb
399
+ - lib/stub_requests/metrics/request.rb
400
+ - lib/stub_requests/observable.rb
401
+ - lib/stub_requests/observable/registry.rb
402
+ - lib/stub_requests/observable/subscription.rb
402
403
  - lib/stub_requests/property.rb
403
404
  - lib/stub_requests/property/validator.rb
404
- - lib/stub_requests/service.rb
405
- - lib/stub_requests/service_registry.rb
405
+ - lib/stub_requests/registration.rb
406
+ - lib/stub_requests/registration/endpoint.rb
407
+ - lib/stub_requests/registration/endpoints.rb
408
+ - lib/stub_requests/registration/registry.rb
409
+ - lib/stub_requests/registration/service.rb
406
410
  - lib/stub_requests/stub_requests.rb
407
411
  - lib/stub_requests/uri.rb
408
412
  - lib/stub_requests/uri/builder.rb
@@ -416,6 +420,7 @@ files:
416
420
  - lib/tasks/gem.rake
417
421
  - lib/tasks/git.rake
418
422
  - stub_requests.gemspec
423
+ - update_docs.sh
419
424
  homepage: https://mhenrixon.github.io/stub_requests/
420
425
  licenses:
421
426
  - MIT
data/bin/update_docs.sh DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- git checkout master
4
- git pull --rebase
5
-
6
- rake yard
7
-
8
- git checkout gh-pages
9
-
10
- shopt -s extglob
11
- rm -rf "$(echo ./!(bin|_config.yml|_index.html))"
12
-
13
- mv doc/* ./
14
- git commit -a -m 'Update documentation'
15
- git push
16
-
@@ -1,159 +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 EndpointRegistry holds a collection of {Endpoint}
12
- #
13
- # @author Mikael Henriksson <mikael@zoolutions.se>
14
- #
15
- class EndpointRegistry
16
- include Enumerable
17
-
18
- #
19
- # @!attribute [rw] endpoints
20
- # @return [Concurrent::Map<Symbol, Endpoint>] a map with endpoints
21
- attr_reader :endpoints
22
-
23
- def initialize
24
- @endpoints = Concurrent::Map.new
25
- end
26
-
27
- #
28
- # Required by Enumerable
29
- #
30
- # @return [Concurrent::Map<Symbol, Service>] a map with endpoints
31
- #
32
- # @yield used by Enumerable
33
- #
34
- def each(&block)
35
- endpoints.each(&block)
36
- end
37
-
38
- #
39
- # Registers an endpoint in the collection
40
- #
41
- # @param [Symbol] endpoint_id the id of this Endpoint
42
- # @param [Symbol] verb a HTTP verb
43
- # @param [String] uri_template the URI to reach the endpoint
44
- # @param [optional, Hash<Symbol>] options default options
45
- #
46
- # @return [Endpoint]
47
- #
48
- # :reek:LongParameterList { max_params: 4 }
49
- def register(endpoint_id, verb, uri_template, options = {})
50
- endpoint =
51
- if (endpoint = find(endpoint_id))
52
- StubRequests.logger.warn("Endpoint already registered: #{endpoint}")
53
- endpoint.update(verb, uri_template, options)
54
- else
55
- Endpoint.new(endpoint_id, verb, uri_template, options)
56
- end
57
-
58
- endpoints[endpoint.id] = endpoint
59
- endpoint
60
- end
61
-
62
- #
63
- # Check if an endpoint is registered
64
- #
65
- # @param [Symbol] endpoint_id the id of the endpoint
66
- #
67
- # @return [true, false]
68
- #
69
- def registered?(endpoint_id)
70
- endpoints[endpoint_id].present?
71
- end
72
-
73
- #
74
- # Updates an endpoint
75
- #
76
- # @param [Symbol] endpoint_id the id of the endpoint
77
- # @param [Symbol] verb a HTTP verb
78
- # @param [String] uri_template how to reach the endpoint
79
- # @param [optional, Hash<Symbol>] options
80
- # @option options [optional, Hash<Symbol>] :request request options
81
- # @option options [optional, Hash<Symbol>] :response options
82
- # @option options [optional, Array, Exception, StandardError, String] :error to raise
83
- # @option options [optional, TrueClass] :timeout raise a timeout error?
84
- #
85
- # @raise [EndpointNotFound] when the endpoint couldn't be found
86
- #
87
- # @return [Endpoint] returns the updated endpoint
88
- #
89
- # :reek:LongParameterList { max_params: 4 }
90
- def update(endpoint_id, verb, uri_template, options)
91
- endpoint = find!(endpoint_id)
92
- endpoint.update(verb, uri_template, options)
93
- end
94
-
95
- #
96
- # Removes an endpoint from the collection
97
- #
98
- # @param [Symbol] endpoint_id the id of the endpoint, `:file_service`
99
- #
100
- # @return [Endpoint] the endpoint that was removed
101
- #
102
- def remove(endpoint_id)
103
- endpoints.delete(endpoint_id)
104
- end
105
-
106
- #
107
- # Fetches an endpoint from the collection
108
- #
109
- # @param [<type>] endpoint_id <description>
110
- #
111
- # @return [Endpoint]
112
- #
113
- def find(endpoint_id)
114
- endpoints[endpoint_id]
115
- end
116
-
117
- #
118
- # Fetches an endpoint from the collection or raises an error
119
- #
120
- # @param [Symbol] endpoint_id the id of the endpoint
121
- #
122
- # @raise [EndpointNotFound] when an endpoint couldn't be found
123
- #
124
- # @return [Endpoint, nil]
125
- #
126
- def find!(endpoint_id)
127
- find(endpoint_id) || raise(EndpointNotFound, "Couldn't find an endpoint with id=:#{endpoint_id}")
128
- end
129
-
130
- #
131
- # Returns a descriptive string with all endpoints in the collection
132
- #
133
- # @return [String]
134
- #
135
- def to_s
136
- [
137
- +"#<#{self.class} endpoints=",
138
- +endpoints_string,
139
- +">",
140
- ].join("")
141
- end
142
-
143
- #
144
- # Returns a nicely formatted string with an array of endpoints
145
- #
146
- #
147
- # @return [<type>] <description>
148
- #
149
- def endpoints_string
150
- "[#{endpoints_as_string}]"
151
- end
152
-
153
- private
154
-
155
- def endpoints_as_string
156
- endpoints.values.map(&:to_s).join(",") if endpoints.size.positive?
157
- end
158
- end
159
- end
@@ -1,77 +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 Service provides details for a registered service
12
- #
13
- # @author Mikael Henriksson <mikael@zoolutions.se>
14
- #
15
- class Service
16
- include Comparable
17
- include Property
18
-
19
- # @!attribute [rw] id
20
- # @return [EndpointRegistry] the id of the service
21
- property :id, type: Symbol
22
-
23
- # @!attribute [rw] uri
24
- # @return [EndpointRegistry] the base uri to the service
25
- property :uri, type: String
26
-
27
- # @!attribute [rw] endpoints
28
- # @return [EndpointRegistry] a list with defined endpoints
29
- attr_reader :endpoints
30
-
31
- #
32
- # Initializes a new instance of a Service
33
- #
34
- # @param [Symbol] service_id the id of this service
35
- # @param [String] service_uri the base uri to reach the service
36
- #
37
- def initialize(service_id, service_uri)
38
- self.id = service_id
39
- self.uri = service_uri
40
- @endpoints = EndpointRegistry.new
41
- end
42
-
43
- #
44
- # Check if the endpoint registry has endpoints
45
- #
46
- # @return [true,false]
47
- #
48
- def endpoints?
49
- endpoints.any?
50
- end
51
-
52
- #
53
- # Returns a nicely formatted string with this service
54
- #
55
- # @return [String]
56
- #
57
- def to_s
58
- [
59
- +"#<#{self.class}",
60
- +" id=#{id}",
61
- +" uri=#{uri}",
62
- +" endpoints=#{endpoints.endpoints_string}",
63
- +">",
64
- ].join("")
65
- end
66
-
67
- def <=>(other)
68
- id <=> other.id
69
- end
70
-
71
- def hash
72
- [id, self.class].hash
73
- end
74
-
75
- alias eql? ==
76
- end
77
- end