nxt_registry 0.1.5 → 0.2.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/.circleci/config.yml +56 -0
- data/.editorconfig +15 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -17
- data/README.md +46 -4
- data/lib/nxt_registry.rb +1 -0
- data/lib/nxt_registry/registry.rb +1 -2
- data/lib/nxt_registry/singleton.rb +17 -0
- data/lib/nxt_registry/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3643055d95f31f6addec18700fd8d7d9157bc4f97848acef8340c11668cfa3df
|
4
|
+
data.tar.gz: 25018d4d1f657991137e0c94bf8afacaca70dcd44008ff6cb96783ea82aa064d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74aefe510917560c5dbc3686834ce64aeb815e8f67d99718f6abf38dd08d639f9a8bba14f3cd2275f7f790b3b853b0207006888ee9303ed4d4b706e99d6e1d8b
|
7
|
+
data.tar.gz: 2225edb2af2a5493b90642934d415115a8577043f69fa329bfe99c0676997d4ad68c023c1c79fc1552519a2ed50a5478ebe440ad936ee5832956a27ebad1caec
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.6.5-node
|
11
|
+
environment:
|
12
|
+
BUNDLER_VERSION: 2.1.4
|
13
|
+
|
14
|
+
working_directory: ~/repo
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- checkout
|
18
|
+
|
19
|
+
# Download and cache dependencies
|
20
|
+
- restore_cache:
|
21
|
+
keys:
|
22
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
23
|
+
|
24
|
+
- run: gem install bundler --version $BUNDLER_VERSION
|
25
|
+
|
26
|
+
- run:
|
27
|
+
name: install dependencies
|
28
|
+
command: |
|
29
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
30
|
+
|
31
|
+
- save_cache:
|
32
|
+
paths:
|
33
|
+
- ./vendor/bundle
|
34
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
35
|
+
|
36
|
+
# run tests!
|
37
|
+
- run:
|
38
|
+
name: run tests
|
39
|
+
command: |
|
40
|
+
mkdir /tmp/test-results
|
41
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
42
|
+
circleci tests split --split-by=timings)"
|
43
|
+
|
44
|
+
bundle exec rspec \
|
45
|
+
--format progress \
|
46
|
+
--format RspecJunitFormatter \
|
47
|
+
--out /tmp/test-results/rspec.xml \
|
48
|
+
--format progress \
|
49
|
+
$TEST_FILES
|
50
|
+
|
51
|
+
# collect reports
|
52
|
+
- store_test_results:
|
53
|
+
path: /tmp/test-results
|
54
|
+
- store_artifacts:
|
55
|
+
path: /tmp/test-results
|
56
|
+
destination: test-results
|
data/.editorconfig
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
2
|
+
|
3
|
+
# top-most EditorConfig file
|
4
|
+
root = true
|
5
|
+
|
6
|
+
# Unix-style newlines with a newline ending every file
|
7
|
+
[*]
|
8
|
+
end_of_line = lf
|
9
|
+
insert_final_newline = true
|
10
|
+
charset = utf-8
|
11
|
+
|
12
|
+
[*.{rb,yml,json,rake}]
|
13
|
+
indent_style = space
|
14
|
+
indent_size = 2
|
15
|
+
trim_trailing_whitespace = true
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# v0.2.0 2020-07-24
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- [internal] Added NxtRegistry::Singleton
|
6
|
+
- Added NxtRegistry::Singleton interface
|
7
|
+
- Make name optional and have object_id.to_s as default name
|
8
|
+
- Fix readme
|
9
|
+
|
10
|
+
[Compare v0.1.5...v0.2.0](https://github.com/nxt-insurance/nxt_registry/compare/v0.1.5...v0.2.0)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,46 +1,48 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_registry (0.
|
4
|
+
nxt_registry (0.2.0)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (6.0.2
|
10
|
+
activesupport (6.0.3.2)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 0.7, < 2)
|
13
13
|
minitest (~> 5.1)
|
14
14
|
tzinfo (~> 1.1)
|
15
|
-
zeitwerk (~> 2.2)
|
16
|
-
coderay (1.1.
|
15
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
16
|
+
coderay (1.1.3)
|
17
17
|
concurrent-ruby (1.1.6)
|
18
|
-
diff-lcs (1.
|
19
|
-
i18n (1.8.
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
i18n (1.8.5)
|
20
20
|
concurrent-ruby (~> 1.0)
|
21
|
-
method_source (0.
|
22
|
-
minitest (5.14.
|
23
|
-
pry (0.
|
24
|
-
coderay (~> 1.1
|
25
|
-
method_source (~>
|
21
|
+
method_source (1.0.0)
|
22
|
+
minitest (5.14.1)
|
23
|
+
pry (0.13.1)
|
24
|
+
coderay (~> 1.1)
|
25
|
+
method_source (~> 1.0)
|
26
26
|
rake (12.3.3)
|
27
27
|
rspec (3.9.0)
|
28
28
|
rspec-core (~> 3.9.0)
|
29
29
|
rspec-expectations (~> 3.9.0)
|
30
30
|
rspec-mocks (~> 3.9.0)
|
31
|
-
rspec-core (3.9.
|
32
|
-
rspec-support (~> 3.9.
|
33
|
-
rspec-expectations (3.9.
|
31
|
+
rspec-core (3.9.2)
|
32
|
+
rspec-support (~> 3.9.3)
|
33
|
+
rspec-expectations (3.9.2)
|
34
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
35
35
|
rspec-support (~> 3.9.0)
|
36
36
|
rspec-mocks (3.9.1)
|
37
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
38
|
rspec-support (~> 3.9.0)
|
39
|
-
rspec-support (3.9.
|
39
|
+
rspec-support (3.9.3)
|
40
|
+
rspec_junit_formatter (0.4.1)
|
41
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
40
42
|
thread_safe (0.3.6)
|
41
|
-
tzinfo (1.2.
|
43
|
+
tzinfo (1.2.7)
|
42
44
|
thread_safe (~> 0.1)
|
43
|
-
zeitwerk (2.
|
45
|
+
zeitwerk (2.4.0)
|
44
46
|
|
45
47
|
PLATFORMS
|
46
48
|
ruby
|
@@ -51,6 +53,7 @@ DEPENDENCIES
|
|
51
53
|
pry
|
52
54
|
rake (~> 12)
|
53
55
|
rspec (~> 3.0)
|
56
|
+
rspec_junit_formatter
|
54
57
|
|
55
58
|
BUNDLED WITH
|
56
59
|
2.1.4
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://circleci.com/gh/nxt-insurance/nxt_registry)
|
2
|
+
|
1
3
|
# NxtRegistry
|
2
4
|
|
3
5
|
NxtRegistry is a simple implementation of the container pattern. It allows you to register and resolve values in nested
|
@@ -21,6 +23,8 @@ Or install it yourself as:
|
|
21
23
|
|
22
24
|
## Usage
|
23
25
|
|
26
|
+
### Instance Level
|
27
|
+
|
24
28
|
```ruby
|
25
29
|
class Example
|
26
30
|
include NxtRegistry
|
@@ -73,6 +77,43 @@ example.passengers.from(:a).to(:b).via(:plane) # => ['Nils', 'Rapha']
|
|
73
77
|
|
74
78
|
```
|
75
79
|
|
80
|
+
Alternatively you can create an instance of NxtRegistry::Registry.new('name', **options, &config)
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
registry = NxtRegistry::Registry.new do
|
84
|
+
register(:andy, 'Andy')
|
85
|
+
register(:anthony, 'Anthony')
|
86
|
+
register(:aki, 'Aki')
|
87
|
+
end
|
88
|
+
|
89
|
+
registry.resolve(:aki) # => 'Aki'
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
### Class Level
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
class SimpleExample
|
97
|
+
# By extending NxtRegistry::Singleton you get a super simple class level interface to an underlying instance of a :registry
|
98
|
+
extend NxtRegistry::Singleton
|
99
|
+
|
100
|
+
registry do
|
101
|
+
# procs are called directly if not defined otherwise
|
102
|
+
register(KeyError, ->(error) { puts 'KeyError handler' } )
|
103
|
+
register(ArgumentError, ->(error) { puts 'ArgumentError handler' } )
|
104
|
+
# Custom key error handlers
|
105
|
+
on_key_already_registered ->(key) { raise "Key was already registered dude: #{key}" }
|
106
|
+
on_key_not_registered ->(key) { raise "Key was never registered dude: #{key}" }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
SimpleExample.resolve(KeyError)
|
111
|
+
# Alternatively: SimpleExample.registry.resolve(KeyError)
|
112
|
+
# Or: SimpleExample.instance.resolve(KeyError)
|
113
|
+
# KeyError handler
|
114
|
+
# => nil
|
115
|
+
|
116
|
+
```
|
76
117
|
|
77
118
|
```ruby
|
78
119
|
class OtherExample
|
@@ -113,7 +154,7 @@ registry :example, default: ->(value) { 'default' }
|
|
113
154
|
|
114
155
|
### Blocks
|
115
156
|
|
116
|
-
When you register a block value that can be called,
|
157
|
+
When you register a block value that can be called, it will automatically be called when you resolve the value.
|
117
158
|
If that's not what you want, you can configure your registry (on each level) not to call blocks directly by defining `call false`
|
118
159
|
|
119
160
|
```ruby
|
@@ -124,7 +165,7 @@ end
|
|
124
165
|
|
125
166
|
### Memoize
|
126
167
|
|
127
|
-
Values are memoized per default. Switch it off with `
|
168
|
+
Values are memoized per default. Switch it off with `memoize: false`
|
128
169
|
|
129
170
|
```ruby
|
130
171
|
registry :example, memoize: false do
|
@@ -141,7 +182,8 @@ registry.resolve(:one)
|
|
141
182
|
|
142
183
|
### Resolver
|
143
184
|
|
144
|
-
You can register a resolver block if you want to lay hands on your values after they have been resolved.
|
185
|
+
You can register a resolver block if you want to lay hands on your values after they have been resolved.
|
186
|
+
A resolver can be anything that implements `:call` to which the value is passed.
|
145
187
|
|
146
188
|
```ruby
|
147
189
|
registry :example do
|
@@ -172,7 +214,7 @@ registry.resolve('BOMBSHELL')
|
|
172
214
|
### Customize registry errors
|
173
215
|
|
174
216
|
You can also customize what kind of errors are being raised in case a of a key was not registered or was already registered.
|
175
|
-
by providing
|
217
|
+
by providing blocks or a handler responding to :call for `on_key_already_registered` and `on_key_already_registered`
|
176
218
|
|
177
219
|
## Development
|
178
220
|
|
data/lib/nxt_registry.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module NxtRegistry
|
2
2
|
class Registry
|
3
|
-
def initialize(name, **options, &config)
|
3
|
+
def initialize(name = object_id.to_s, **options, &config)
|
4
4
|
@name = name
|
5
5
|
@parent = options[:parent]
|
6
6
|
@is_leaf = true
|
@@ -133,7 +133,6 @@ module NxtRegistry
|
|
133
133
|
|
134
134
|
raise ArgumentError, "Not allowed to register values in a registry that contains nested registries" unless is_leaf
|
135
135
|
raise KeyError, "Keys are restricted to #{attrs.keys}" if attribute_not_allowed?(key)
|
136
|
-
|
137
136
|
on_key_already_registered && on_key_already_registered.call(key) if store[key] && raise
|
138
137
|
|
139
138
|
store[key] = value
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NxtRegistry
|
2
|
+
module Singleton
|
3
|
+
def self.extended(subclass)
|
4
|
+
subclass.singleton_class.class_eval do
|
5
|
+
default_name = (subclass.name || 'registry')
|
6
|
+
|
7
|
+
define_method :registry do |name = default_name, **options, &block|
|
8
|
+
@registry ||= NxtRegistry::Registry.new(name, **options, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
delegate_missing_to :registry
|
12
|
+
|
13
|
+
define_method(:instance) { registry }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/nxt_registry/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nxt_registry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Robecke
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-
|
14
|
+
date: 2020-07-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -90,10 +90,13 @@ executables: []
|
|
90
90
|
extensions: []
|
91
91
|
extra_rdoc_files: []
|
92
92
|
files:
|
93
|
+
- ".circleci/config.yml"
|
94
|
+
- ".editorconfig"
|
93
95
|
- ".gitignore"
|
94
96
|
- ".rakeTasks"
|
95
97
|
- ".rspec"
|
96
98
|
- ".travis.yml"
|
99
|
+
- CHANGELOG.md
|
97
100
|
- Gemfile
|
98
101
|
- Gemfile.lock
|
99
102
|
- LICENSE.txt
|
@@ -108,6 +111,7 @@ files:
|
|
108
111
|
- lib/nxt_registry/nested_registry_builder.rb
|
109
112
|
- lib/nxt_registry/recursive_registry.rb
|
110
113
|
- lib/nxt_registry/registry.rb
|
114
|
+
- lib/nxt_registry/singleton.rb
|
111
115
|
- lib/nxt_registry/version.rb
|
112
116
|
- nxt_registry.gemspec
|
113
117
|
homepage: https://github.com/nxt-insurance
|