nxt_registry 0.3.3 → 0.3.4

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
  SHA256:
3
- metadata.gz: 1f83b8d92a02103b69d4746dfb08e396d827992bc1d1ef21d39fd46d117ce2ac
4
- data.tar.gz: ab40f633dbed120132de18dbec3b1707c2cab85114ff5857330add4845db0209
3
+ metadata.gz: b3c4dec7379f1076565a8fa2306e9aba2bfbd12f1191648929635db61a7b4a94
4
+ data.tar.gz: '081a471bb51c5e53089ee8341f439b8b70bdb22bb45c24add42673210ecacd0c'
5
5
  SHA512:
6
- metadata.gz: 9f843eec28980bd3ffd49906b0661cdce4a02f4a027cf48845cfff799fcbd58213260790501a104435ec71b7e7261f9ff49239dd1296af1f40dcec383de99a29
7
- data.tar.gz: 71cb8513d2eb829bf930a96e244bc6914dbc9f62a78e5fa7916ffc0710765c6393063b055779d22226d718bc52c52fd106f7a3ed8ad44536768a58f28968fe56
6
+ metadata.gz: 7913f84e7bfea3f58efd487eb9bbdc34c988fb3297101aa52525e530c8a6bec5b2d5bc6dfc81bd188f4145c99a74dbbb65b556b6acf847b16df529a65b612999
7
+ data.tar.gz: 59fe97c3fe3bbc653bd63f6e7bd835d08189136fc328d9ce0fa62e8199dcc311fa152d2d0ebedb1b7a580b3ef20a6253dfbb02c605a700f88a42076bd57935be
@@ -1,3 +1,8 @@
1
+ # v0.3.4 2020-12-04
2
+
3
+ - Bring back Singleton
4
+ - Fix mistakes in readme
5
+
1
6
  # v0.3.3 2020-11-24
2
7
 
3
8
  - Fix: Pass key to resolver instead of value
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_registry (0.3.3)
4
+ nxt_registry (0.3.4)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -42,7 +42,7 @@ GEM
42
42
  thread_safe (0.3.6)
43
43
  tzinfo (1.2.8)
44
44
  thread_safe (~> 0.1)
45
- zeitwerk (2.4.1)
45
+ zeitwerk (2.4.2)
46
46
 
47
47
  PLATFORMS
48
48
  ruby
data/README.md CHANGED
@@ -27,24 +27,23 @@ Or install it yourself as:
27
27
 
28
28
  ## Instance Level
29
29
 
30
- To use `NxtRegistry` on an instance level simply include it and build registries like so:
30
+ If you simply need a single global instance of a registry include `NxtRegistry::Singleton`:
31
31
 
32
32
  ```ruby
33
33
  class Example
34
- include NxtRegistry
34
+ include NxtRegistry::Singleton
35
35
 
36
- registry :languages do
36
+ registry do
37
37
  register(:ruby, 'Stone')
38
38
  register(:python, 'Snake')
39
39
  register(:javascript, 'undefined')
40
40
  end
41
41
  end
42
42
 
43
- example = Example.new
44
- example.registry(:languages).resolve(:ruby) # => 'Stone'
43
+ Example.resolve(:ruby) # => 'Stone'
45
44
  ```
46
45
 
47
- Alternatively you can also create instances of `NxtRegistry::Registry`
46
+ Alternatively you can simply create instances of `NxtRegistry::Registry`:
48
47
 
49
48
  ```ruby
50
49
  registry = NxtRegistry::Registry.new do
@@ -59,7 +58,7 @@ registry.resolve(:aki) # => 'Aki'
59
58
 
60
59
  ## Class Level
61
60
 
62
- You can add registries on the class level simply by extending your class with `NxtRegistry`
61
+ You can also add registries on the class level simply by extending your class with `NxtRegistry`
63
62
 
64
63
  ```ruby
65
64
  class OtherExample
@@ -6,6 +6,7 @@ require 'nxt_registry/errors'
6
6
  require 'nxt_registry/registry_builder'
7
7
  require 'nxt_registry/registry'
8
8
  require 'nxt_registry/recursive_registry'
9
+ require 'nxt_registry/singleton'
9
10
 
10
11
  module NxtRegistry
11
12
  def registry(name, **options, &config)
@@ -19,17 +20,17 @@ module NxtRegistry
19
20
  private
20
21
 
21
22
  def build_registry(registry_class, name, **options, &config)
22
- if registries.key?(name)
23
- registry = registries.fetch(name)
23
+ registry = registries.resolve(name)
24
+
25
+ if registry.present?
24
26
  if registry.configured
25
- registry
27
+ return registry
26
28
  else
27
29
  raise_unconfigured_registry_accessed(name)
28
30
  end
29
31
  else
30
32
  registry = registry_class.new(name, **options, &config)
31
- registries[name] ||= registry
32
- registry
33
+ registries.register(name, registry)
33
34
  end
34
35
  end
35
36
 
@@ -38,6 +39,6 @@ module NxtRegistry
38
39
  end
39
40
 
40
41
  def registries
41
- @registries ||= {}
42
+ @registries ||= Registry.new(:registries)
42
43
  end
43
44
  end
@@ -0,0 +1,15 @@
1
+ module NxtRegistry
2
+ module Singleton
3
+ include NxtRegistry
4
+
5
+ def self.included(base)
6
+ base.extend(self)
7
+ end
8
+
9
+ def registry(type = Registry, **options, &config)
10
+ @registry ||= build_registry(type, self.class.name, **options, &config)
11
+ end
12
+
13
+ delegate_missing_to :registry
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module NxtRegistry
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
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.3.3
4
+ version: 0.3.4
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-11-24 00:00:00.000000000 Z
14
+ date: 2020-12-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -112,6 +112,7 @@ files:
112
112
  - lib/nxt_registry/recursive_registry.rb
113
113
  - lib/nxt_registry/registry.rb
114
114
  - lib/nxt_registry/registry_builder.rb
115
+ - lib/nxt_registry/singleton.rb
115
116
  - lib/nxt_registry/version.rb
116
117
  - nxt_registry.gemspec
117
118
  homepage: https://github.com/nxt-insurance