artirix_data_models 0.32.0 → 1.0.0.beta1

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
  SHA1:
3
- metadata.gz: 68ae21ecebbb6e23b0e20e3cc9aed1dfbe0932ea
4
- data.tar.gz: d9e1ff08adcb57dee94cea2b69cabde6483d8451
3
+ metadata.gz: b24c8e95bc1bd45a7df4207da2d02673adb6f721
4
+ data.tar.gz: 7bbe651de9dcdeb677687ad0839c10a2b1b45d14
5
5
  SHA512:
6
- metadata.gz: e2adcab677b934257e58d7579a4b65ef46b97033b6b1caf8b16e86f2bbd07dd1cf7acd503c0d46488669f9d073ab7c6614694783280200976f37b29cb179d43e
7
- data.tar.gz: c2f3b98d7b7d9a7c1e4eb428edc936083bb754d965a3a021a818d9a8054b87b3f8b74f16dc818c6cc42c2cfb4c3a32a70f113839413aff3e3aff13957be1409d
6
+ metadata.gz: 2065f4af7b36c022d2160d899ed4535b8cefe5764f3eabc282a48750d5b0616c1f16ee72d786c53d0c5cb8be226fbba7aeca6c1615f194057279a73384f74a4c
7
+ data.tar.gz: 213acba354ebaca8c02116674c08aa9b6db758c78f705250f67ddac5dc8c99765f9dd9a9d96cc9cf8059d94482e90c90867c0516abb2b4ad2492b38fe7aa5eee
data/.travis.yml CHANGED
@@ -7,7 +7,7 @@ addons:
7
7
  code_climate:
8
8
  repo_token: 84e47c3e41ba9fbc2d639c167be45aa3f6c077374015309dac005ab51f713d83
9
9
 
10
- script: 'bundle exec rake spec'
10
+ script: 'bundle exec rake'
11
11
 
12
12
  notifications:
13
13
  email:
data/Gemfile CHANGED
@@ -17,3 +17,4 @@ group :test do
17
17
  end
18
18
 
19
19
  gem 'codeclimate-test-reporter', group: :test, require: nil
20
+ gem 'simplecov'
data/README.md CHANGED
@@ -131,7 +131,7 @@ TODO:
131
131
 
132
132
  ### The Registry
133
133
 
134
- Your app should extend the `ArtirixDataModels::DAORegistry`. We can override the `setup_config` method to add extra loaders.
134
+ Your app should extend the `ArtirixDataModels::ADMRegistry`. We can override the `setup_config` method to add extra loaders.
135
135
 
136
136
  **important: do not forget to call `super` on `setup_config`.**
137
137
 
@@ -140,7 +140,7 @@ Also, the Registry class that you want to use in your app should have in its def
140
140
  You can add loaders that will be called only and memoized with `set_persistent_loader` and loaders that will cbe called every time with `set_transient_loader`. `se_loader` is an alias of `set_persistent_loader`.
141
141
 
142
142
  ```ruby
143
- class DAORegistry < ArtirixDataModels::DAORegistry
143
+ class ADMRegistry < ArtirixDataModels::ADMRegistry
144
144
  def setup_config
145
145
  super
146
146
 
@@ -161,13 +161,13 @@ class DAORegistry < ArtirixDataModels::DAORegistry
161
161
  end
162
162
  ```
163
163
 
164
- You can use the DAORegistry by invoking it directly (or calling its instance) `DAORegistry.get(:name)` or `DAORegistry.instance.get(:name)`.
164
+ You can use the ADMRegistry by invoking it directly (or calling its instance) `ADMRegistry.get(:name)` or `ADMRegistry.instance.get(:name)`.
165
165
 
166
166
  You can also use an identity map mode (see bellow)
167
167
 
168
168
  ### Identity Map
169
169
 
170
- You can use `dao_registry = DAORegistry.with_identity_map`. Then, the DAO's default methods `get`, `find` and `get_some` will register the loaded models into the DAO, acting as an identity map, and will also use that identity map to check for the existence of models with those PKs, returning them if they are found.
170
+ You can use `adm_registry = ADMRegistry.with_identity_map`. Then, the DAO's default methods `get`, `find` and `get_some` will register the loaded models into the DAO, acting as an identity map, and will also use that identity map to check for the existence of models with those PKs, returning them if they are found.
171
171
 
172
172
  The Identity Map does not have a TTL, so use it only with transient DAOs -> you don't want the identity map to live between requests, since that will mean that the models will never be forgotten, not being able to see new fresh versions, with the extra problem of memory leak.
173
173
 
@@ -269,8 +269,8 @@ require File.expand_path("../../config/environment", __FILE__)
269
269
  require 'rspec/rails'
270
270
  # Add additional requires below this line. Rails is not loaded until this point!
271
271
 
272
- # force the use of the custom DAORegistry
273
- require 'dao_registry'
272
+ # force the use of the custom ADMRegistry
273
+ require 'adm_registry'
274
274
  ```
275
275
 
276
276
  #### Spec Support
@@ -327,6 +327,14 @@ end
327
327
 
328
328
  ## Changes
329
329
 
330
+ ### Breaking Changes!!: version 1.0.0.beta1
331
+
332
+ - rename `DAORegistry` to `ADMRegistry`, and `dao_registry` to `adm_registry`. Passed the rename to all places (`adm_registry_loader`, etc.)
333
+
334
+ - Registry changes:
335
+ - instance is thread safe controlled by a class level mutex, shared across all subclasses
336
+ - instance level mutexes to control changes in persistent (setting new persistent loader or saving in local registry a persisted value) and transient (setting new transient loader).
337
+
330
338
  ### 0.32.0
331
339
 
332
340
  - minor changes to allow backwards compatibility. Better mocking of gateway.
@@ -1,22 +1,36 @@
1
- class ArtirixDataModels::DAORegistry
1
+ class ArtirixDataModels::ADMRegistry
2
+ @instance_mutex = Mutex.new
3
+
4
+ def self.instance_mutex
5
+ ArtirixDataModels::ADMRegistry.instance_variable_get :@instance_mutex
6
+ end
2
7
 
3
8
  def self.instance
4
- @__instance ||= new
9
+ instance_mutex.synchronize {
10
+ @instance = new unless @instance
11
+ @instance
12
+ }
5
13
  end
6
14
 
7
15
  def self.instance=(x)
8
- @__instance = x
16
+ instance_mutex.synchronize {
17
+ @instance = x
18
+ @instance
19
+ }
9
20
  end
10
21
 
11
22
  def self.mark_as_main_registry
12
- ArtirixDataModels::DAORegistry.instance = self.instance
23
+ ArtirixDataModels::ADMRegistry.instance = self.instance
13
24
  end
14
25
 
15
26
  # singleton instance
16
27
  def initialize
17
- @_repository = {}
18
- @_persistent_loaders = {}
19
- @_transient_loaders = {}
28
+ @persistent_mutex = Mutex.new
29
+ @transient_mutex = Mutex.new
30
+
31
+ @repository = {}
32
+ @persistent_loaders = {}
33
+ @transient_loaders = {}
20
34
 
21
35
  setup_config
22
36
  end
@@ -46,13 +60,13 @@ class ArtirixDataModels::DAORegistry
46
60
 
47
61
  def exist?(key)
48
62
  key = key.to_sym
49
- @_repository.key?(key) || @_persistent_loaders.key?(key) || @_transient_loaders.key?(key)
63
+ repository_has_key?(key) || has_persistent_loader?(key) || has_transient_loader?(key)
50
64
  end
51
65
 
52
- def get(key, override_dao_registry: nil)
53
- x = @_repository[key.to_sym] || call_loader(key)
54
- if x.present? && override_dao_registry.present? && x.respond_to?(:set_dao_registry)
55
- x.set_dao_registry override_dao_registry
66
+ def get(key, override_adm_registry: nil)
67
+ x = @repository[key.to_sym] || call_loader(key)
68
+ if x.present? && override_adm_registry.present? && x.respond_to?(:set_adm_registry)
69
+ x.set_adm_registry override_adm_registry
56
70
  end
57
71
 
58
72
  x
@@ -62,24 +76,28 @@ class ArtirixDataModels::DAORegistry
62
76
  key = key.to_sym
63
77
 
64
78
  if block
65
- @_transient_loaders[key] = block
79
+ value_to_store = block
66
80
  elsif loader.respond_to? :call
67
- @_transient_loaders[key] = loader
81
+ value_to_store = loader
68
82
  else
69
83
  raise ArgumentError, "no block and no loader given for key #{key}"
70
84
  end
85
+
86
+ @transient_mutex.synchronize { @transient_loaders[key] = value_to_store }
71
87
  end
72
88
 
73
89
  def set_persistent_loader(key, loader = nil, &block)
74
90
  key = key.to_sym
75
91
 
76
92
  if block
77
- @_persistent_loaders[key] = block
93
+ value_to_store = block
78
94
  elsif loader.respond_to? :call
79
- @_persistent_loaders[key] = loader
95
+ value_to_store = loader
80
96
  else
81
97
  raise ArgumentError, "no block and no loader given for key #{key}"
82
98
  end
99
+
100
+ @persistent_mutex.synchronize { @persistent_loaders[key] = value_to_store }
83
101
  end
84
102
 
85
103
  alias_method :set_loader, :set_persistent_loader
@@ -89,7 +107,7 @@ class ArtirixDataModels::DAORegistry
89
107
  ################
90
108
 
91
109
  def with_identity_map
92
- IdentityMap.new dao_registry: self
110
+ IdentityMap.new adm_registry: self
93
111
  end
94
112
 
95
113
  # IDENTITY MAP compatible
@@ -111,15 +129,29 @@ class ArtirixDataModels::DAORegistry
111
129
  private
112
130
  def call_loader(key)
113
131
  key = key.to_sym
114
- if @_persistent_loaders[key]
115
- @_repository[key] = @_persistent_loaders[key].call
116
- elsif @_transient_loaders[key]
117
- @_transient_loaders[key].call
132
+ if @persistent_loaders[key]
133
+ @persistent_loaders[key].call.tap do |value_to_store|
134
+ @persistent_mutex.synchronize { @repository[key] = value_to_store }
135
+ end
136
+ elsif @transient_loaders[key]
137
+ @transient_loaders[key].call
118
138
  else
119
139
  raise LoaderNotFound, "no loader or transient found for #{key}"
120
140
  end
121
141
  end
122
142
 
143
+ def has_transient_loader?(key)
144
+ @transient_loaders.key?(key)
145
+ end
146
+
147
+ def has_persistent_loader?(key)
148
+ @persistent_loaders.key?(key)
149
+ end
150
+
151
+ def repository_has_key?(key)
152
+ @repository.key?(key)
153
+ end
154
+
123
155
 
124
156
  # static methods
125
157
 
@@ -163,10 +195,10 @@ class ArtirixDataModels::DAORegistry
163
195
  end
164
196
 
165
197
  class IdentityMap
166
- include ArtirixDataModels::WithDAORegistry
198
+ include ArtirixDataModels::WithADMRegistry
167
199
 
168
- def initialize(dao_registry_loader: nil, dao_registry: nil)
169
- set_dao_registry_and_loader dao_registry_loader, dao_registry
200
+ def initialize(adm_registry_loader: nil, adm_registry: nil)
201
+ set_adm_registry_and_loader adm_registry_loader, adm_registry
170
202
  @identity_map = {}
171
203
  end
172
204
 
@@ -174,19 +206,19 @@ class ArtirixDataModels::DAORegistry
174
206
  # DELEGATING TO DAO REGISTRY #
175
207
  ##############################
176
208
 
177
- delegate :exist?, :aggregations_factory, to: :dao_registry
209
+ delegate :exist?, :aggregations_factory, to: :adm_registry
178
210
 
179
211
  def respond_to_missing?(method_name, include_private = false)
180
- dao_registry.respond_to? method_name, include_private
212
+ adm_registry.respond_to? method_name, include_private
181
213
  end
182
214
 
183
215
  def method_missing(method_name, *arguments, &block)
184
- dao_registry.send method_name, *arguments, &block
216
+ adm_registry.send method_name, *arguments, &block
185
217
  end
186
218
 
187
- def get(key, override_dao_registry: nil)
188
- override_dao_registry ||= self
189
- dao_registry.get key, override_dao_registry: override_dao_registry
219
+ def get(key, override_adm_registry: nil)
220
+ override_adm_registry ||= self
221
+ adm_registry.get key, override_adm_registry: override_adm_registry
190
222
  end
191
223
 
192
224
  ###########################
@@ -241,7 +273,7 @@ class ArtirixDataModels::DAORegistry
241
273
 
242
274
  def keys_from_model(model, action: :use)
243
275
  model_dao_name = model.try :model_dao_name
244
- primary_key = model.try :primary_key
276
+ primary_key = model.try :primary_key
245
277
 
246
278
  if model_dao_name.blank?
247
279
  ArtirixDataModels.logger.error("model does not have a `model_dao_name` #{model}: we cannot #{action} it")
@@ -1,7 +1,7 @@
1
1
  module ArtirixDataModels
2
2
  class CommonAggregation
3
3
  include Inspectable
4
- include ArtirixDataModels::WithDAORegistry
4
+ include ArtirixDataModels::WithADMRegistry
5
5
 
6
6
  attr_accessor :name
7
7
 
@@ -12,7 +12,7 @@ module ArtirixDataModels
12
12
  # DEPRECATED
13
13
  def self.from_json(definition, value_class = Aggregation::Value, aggregations_factory: nil)
14
14
  ActiveSupport::Deprecation.new('1.0', 'ArtirixDataModels').warn('`Aggregation.from_json` is deprecated in favour of `AggregationsFactory#aggregation_from_json`')
15
- aggregations_factory ||= DAORegistry.get(:aggregations_factory)
15
+ aggregations_factory ||= ADMRegistry.get(:aggregations_factory)
16
16
  aggregations_factory.aggregation_from_json(definition, value_class: value_class, aggregation_class: self)
17
17
  end
18
18
 
@@ -2,7 +2,7 @@ module ArtirixDataModels
2
2
  class AggregationsFactory
3
3
  DEFAULT_COLLECTION_CLASS_NAME = ''.freeze
4
4
 
5
- include ArtirixDataModels::WithDAORegistry
5
+ include ArtirixDataModels::WithADMRegistry
6
6
 
7
7
  # AGGREGATION CLASS BUILDING
8
8
 
@@ -28,27 +28,27 @@ module ArtirixDataModels
28
28
  :perform_put,
29
29
  :perform_delete,
30
30
 
31
- :dao_registry,
32
- :dao_registry=,
33
- :set_dao_registry,
34
- :dao_registry_loader,
35
- :dao_registry_loader=,
36
- :set_dao_registry_loader,
37
- :set_default_dao_registry_loader,
38
- :set_default_dao_registry,
31
+ :adm_registry,
32
+ :adm_registry=,
33
+ :set_adm_registry,
34
+ :adm_registry_loader,
35
+ :adm_registry_loader=,
36
+ :set_adm_registry_loader,
37
+ :set_default_adm_registry_loader,
38
+ :set_default_adm_registry,
39
39
  ]
40
40
 
41
41
  included do
42
42
  include ArtirixDataModels::DAOConcerns::WithResponseAdaptors
43
- include ArtirixDataModels::WithDAORegistry
43
+ include ArtirixDataModels::WithADMRegistry
44
44
 
45
45
  attr_reader :basic_model_dao
46
46
  delegate *DELEGATED_METHODS, to: :basic_model_dao
47
47
  end
48
48
 
49
49
 
50
- def initialize(dao_registry: nil,
51
- dao_registry_loader: nil,
50
+ def initialize(adm_registry: nil,
51
+ adm_registry_loader: nil,
52
52
  gateway: nil,
53
53
  gateway_factory: nil,
54
54
  ignore_default_gateway: false,
@@ -63,8 +63,8 @@ module ArtirixDataModels
63
63
  fake_mode_factory ||= default_fake_mode_factory
64
64
 
65
65
  # temporary dao registry to load basic_class only
66
- create_basic_model_dao dao_registry: dao_registry,
67
- dao_registry_loader: dao_registry_loader,
66
+ create_basic_model_dao adm_registry: adm_registry,
67
+ adm_registry_loader: adm_registry_loader,
68
68
  fake_mode_factory: fake_mode_factory,
69
69
  gateway: gateway,
70
70
  gateway_factory: gateway_factory,
@@ -75,8 +75,8 @@ module ArtirixDataModels
75
75
 
76
76
  end
77
77
 
78
- def create_basic_model_dao(dao_registry:,
79
- dao_registry_loader:,
78
+ def create_basic_model_dao(adm_registry:,
79
+ adm_registry_loader:,
80
80
  fake_mode_factory:,
81
81
  gateway:,
82
82
  gateway_factory:,
@@ -86,8 +86,8 @@ module ArtirixDataModels
86
86
  paths_factory:,
87
87
  **other_basic_model_dao_params)
88
88
 
89
- dr = ArtirixDataModels::WithDAORegistry.loader_or_registry_or_default dao_registry_loader: dao_registry_loader,
90
- dao_registry: dao_registry
89
+ dr = ArtirixDataModels::WithADMRegistry.loader_or_registry_or_default adm_registry_loader: adm_registry_loader,
90
+ adm_registry: adm_registry
91
91
 
92
92
  basic_model_class = dr.get(:basic_class)
93
93
 
@@ -97,8 +97,8 @@ module ArtirixDataModels
97
97
  paths_factory: paths_factory,
98
98
  gateway: gateway,
99
99
  gateway_factory: gateway_factory,
100
- dao_registry: dao_registry,
101
- dao_registry_loader: dao_registry_loader,
100
+ adm_registry: adm_registry,
101
+ adm_registry_loader: adm_registry_loader,
102
102
  ignore_default_gateway: ignore_default_gateway,
103
103
  **other_basic_model_dao_params
104
104
  end
@@ -153,7 +153,7 @@ module ArtirixDataModels
153
153
  end
154
154
 
155
155
  def get(model_pk, cache_adaptor: nil, **extra_options)
156
- model = dao_registry.get_model model_name, model_pk
156
+ model = adm_registry.get_model model_name, model_pk
157
157
  return model if model.present?
158
158
 
159
159
  cache_adaptor ||= cache_model_adaptor_for_get(model_pk, **extra_options)
@@ -164,7 +164,7 @@ module ArtirixDataModels
164
164
  end
165
165
 
166
166
  def find(model_pk, cache_adaptor: nil, **extra_options)
167
- model = dao_registry.get_model model_name, model_pk
167
+ model = adm_registry.get_model model_name, model_pk
168
168
  return model if model.present?
169
169
 
170
170
  cache_adaptor ||= cache_model_adaptor_for_find(model_pk, **extra_options)
@@ -178,7 +178,7 @@ module ArtirixDataModels
178
178
  registered = Array(model_pks).map do |model_pk|
179
179
  [
180
180
  model_pk,
181
- dao_registry.get_model(model_name, model_pk)
181
+ adm_registry.get_model(model_name, model_pk)
182
182
  ]
183
183
  end.to_h
184
184
 
@@ -230,8 +230,8 @@ module ArtirixDataModels
230
230
 
231
231
  def complete_model(model)
232
232
  if model
233
- dao_registry.register_model model
234
- model.try :set_dao_registry_loader, dao_registry_loader
233
+ adm_registry.register_model model
234
+ model.try :set_adm_registry_loader, adm_registry_loader
235
235
  end
236
236
 
237
237
  model
@@ -25,7 +25,7 @@ module ArtirixDataModels
25
25
  end
26
26
 
27
27
  def response_adaptor_for_collection(from, size, collection_element_model_class = model_class)
28
- model_adaptor_factory.collection collection_element_model_class, from, size, dao_registry_loader
28
+ model_adaptor_factory.collection collection_element_model_class, from, size, adm_registry_loader
29
29
  end
30
30
 
31
31
  def response_adaptor_for_block(&block)
@@ -1,11 +1,11 @@
1
1
  class ArtirixDataModels::BasicModelDAO
2
2
  include ArtirixDataModels::DAOConcerns::WithResponseAdaptors
3
- include ArtirixDataModels::WithDAORegistry
3
+ include ArtirixDataModels::WithADMRegistry
4
4
 
5
5
  attr_reader :model_name, :model_class, :paths_factory, :fake_mode_factory, :gateway_factory
6
6
 
7
- def initialize(dao_registry: nil,
8
- dao_registry_loader: nil,
7
+ def initialize(adm_registry: nil,
8
+ adm_registry_loader: nil,
9
9
  model_name:,
10
10
  model_class:,
11
11
  paths_factory:,
@@ -14,7 +14,7 @@ class ArtirixDataModels::BasicModelDAO
14
14
  gateway_factory:,
15
15
  ignore_default_gateway: false)
16
16
 
17
- set_dao_registry_and_loader dao_registry_loader, dao_registry
17
+ set_adm_registry_and_loader adm_registry_loader, adm_registry
18
18
 
19
19
  @model_name = model_name
20
20
  @model_class = model_class
@@ -31,7 +31,7 @@ class ArtirixDataModels::BasicModelDAO
31
31
 
32
32
  def loaded_gateway
33
33
  @loaded_gateway ||= if gateway_factory.blank? && default_gateway_available?
34
- dao_registry.get(:gateway)
34
+ adm_registry.get(:gateway)
35
35
  end
36
36
  end
37
37
 
@@ -95,7 +95,7 @@ class ArtirixDataModels::BasicModelDAO
95
95
  if fake?
96
96
  fake_mode_factory.partial_mode_fields
97
97
  else
98
- dao_registry.get(:model_fields).partial_mode_fields_for model_name
98
+ adm_registry.get(:model_fields).partial_mode_fields_for model_name
99
99
  end
100
100
  end
101
101
 
@@ -7,15 +7,15 @@
7
7
  class ArtirixDataModels::ModelFieldsDAO
8
8
  PARTIAL_FIELDS = {}
9
9
 
10
- include ArtirixDataModels::WithDAORegistry
10
+ include ArtirixDataModels::WithADMRegistry
11
11
 
12
- def initialize(dao_registry: nil, dao_registry_loader: nil, gateway: nil)
13
- set_dao_registry_and_loader dao_registry_loader, dao_registry
12
+ def initialize(adm_registry: nil, adm_registry_loader: nil, gateway: nil)
13
+ set_adm_registry_and_loader adm_registry_loader, adm_registry
14
14
  @gateway = gateway
15
15
  end
16
16
 
17
17
  def gateway
18
- @gateway ||= dao_registry.gateway
18
+ @gateway ||= adm_registry.gateway
19
19
  end
20
20
 
21
21
  def partial_mode_fields_for(model_name)
@@ -66,7 +66,7 @@ module ArtirixDataModels
66
66
  end
67
67
 
68
68
  include Enumerable
69
- include ArtirixDataModels::WithDAORegistry
69
+ include ArtirixDataModels::WithADMRegistry
70
70
 
71
71
  attr_reader :klass_or_factory, :response, :from, :size
72
72
 
@@ -80,11 +80,11 @@ module ArtirixDataModels
80
80
  response:,
81
81
  from: 0,
82
82
  size: DEFAULT_SIZE,
83
- dao_registry: nil,
84
- dao_registry_loader: nil,
83
+ adm_registry: nil,
84
+ adm_registry_loader: nil,
85
85
  aggregations_factory: nil)
86
86
 
87
- set_dao_registry_and_loader dao_registry_loader, dao_registry
87
+ set_adm_registry_and_loader adm_registry_loader, adm_registry
88
88
 
89
89
  @klass_or_factory = klass_or_factory
90
90
  @response = response
@@ -94,7 +94,7 @@ module ArtirixDataModels
94
94
  end
95
95
 
96
96
  def aggregations_factory
97
- @aggregations_factory || dao_registry.get(:aggregations_factory)
97
+ @aggregations_factory || adm_registry.get(:aggregations_factory)
98
98
  end
99
99
 
100
100
  # The number of total hits for a query
@@ -192,8 +192,8 @@ module ArtirixDataModels
192
192
 
193
193
  def complete_model(model)
194
194
  if model
195
- dao_registry.register_model model
196
- model.try :set_dao_registry_loader, dao_registry_loader
195
+ adm_registry.register_model model
196
+ model.try :set_adm_registry_loader, adm_registry_loader
197
197
  end
198
198
 
199
199
  model
@@ -52,14 +52,14 @@ module ArtirixDataModels::GatewayResponseAdaptors
52
52
  new ->(data_list) { Array(data_list).map { |data_hash| model_class.new data_hash } }
53
53
  end
54
54
 
55
- def self.collection(object_class_or_factory, from = 0, size = nil, dao_registry_loader = nil)
55
+ def self.collection(object_class_or_factory, from = 0, size = nil, adm_registry_loader = nil)
56
56
  size ||= ArtirixDataModels.configuration.try(:search_page_size).try(:default) || 10
57
57
  new ->(data_collection) {
58
58
  ArtirixDataModels::EsCollection.new object_class_or_factory,
59
59
  response: data_collection,
60
60
  from: from,
61
61
  size: size,
62
- dao_registry_loader: dao_registry_loader
62
+ adm_registry_loader: adm_registry_loader
63
63
  }
64
64
  end
65
65
 
@@ -325,11 +325,11 @@ module ArtirixDataModels
325
325
  extend ActiveSupport::Concern
326
326
 
327
327
  included do
328
- include ArtirixDataModels::WithDAORegistry
328
+ include ArtirixDataModels::WithADMRegistry
329
329
  end
330
330
 
331
- def initialize(dao_registry: nil, dao_registry_loader: nil, **properties)
332
- set_dao_registry_and_loader dao_registry_loader, dao_registry
331
+ def initialize(adm_registry: nil, adm_registry_loader: nil, **properties)
332
+ set_adm_registry_and_loader adm_registry_loader, adm_registry
333
333
  _set_properties properties
334
334
  end
335
335
 
@@ -349,7 +349,7 @@ module ArtirixDataModels
349
349
  def load_dao
350
350
  key = self.class.dao_name
351
351
  raise UndefinedDAOError, "`dao_name` not defined for #{self.class}" unless key.present?
352
- dao_registry.get(key)
352
+ adm_registry.get(key)
353
353
  end
354
354
 
355
355
  module ClassMethods
@@ -27,10 +27,12 @@ def mock_gateway_response(response:,
27
27
  authorization_bearer: nil,
28
28
  authorization_token_hash: nil,
29
29
  gateway: nil,
30
+ gateway_repository_name: :gateway,
30
31
  headers: nil,
31
32
  expect: false,
32
33
  &block)
33
- gateway ||= ArtirixDataModels::DAORegistry.gateway
34
+
35
+ gateway ||= ArtirixDataModels::ADMRegistry.instance.get(gateway_repository_name)
34
36
 
35
37
  callable = block_given? ? block : ->(x) { x }
36
38
 
@@ -65,9 +67,10 @@ def mock_gateway_not_found_response(method:,
65
67
  authorization_bearer: nil,
66
68
  authorization_token_hash: nil,
67
69
  gateway: nil,
70
+ gateway_repository_name: :gateway,
68
71
  headers: nil)
69
72
 
70
- gateway ||= ArtirixDataModels::DAORegistry.gateway
73
+ gateway ||= ArtirixDataModels::ADMRegistry.instance.get(gateway_repository_name)
71
74
 
72
75
  params_hash = {
73
76
  path: path,
@@ -98,7 +98,7 @@ shared_examples_for 'an ArtirixDataModel DAO' do
98
98
  end
99
99
 
100
100
  Given do
101
- allow(subject.dao_registry).to receive(:get).with(:model_fields).and_return(model_fields_dao)
101
+ allow(subject.adm_registry).to receive(:get).with(:model_fields).and_return(model_fields_dao)
102
102
  end
103
103
 
104
104
  When(:result) { subject.partial_mode_fields }
@@ -1,3 +1,3 @@
1
1
  module ArtirixDataModels
2
- VERSION = '0.32.0'
2
+ VERSION = '1.0.0.beta1'
3
3
  end
@@ -0,0 +1,73 @@
1
+ module ArtirixDataModels::WithADMRegistry
2
+ DEFAULT_DAO_REGISTRY_LOADER = ->() { ArtirixDataModels::ADMRegistry.instance }
3
+
4
+ def self.loader_or_registry_or_default(adm_registry: nil, adm_registry_loader: nil)
5
+ raise ArgumentError, 'loader has to respond to :call' if adm_registry_loader.present? && !adm_registry_loader.respond_to?(:call)
6
+
7
+ if adm_registry_loader.respond_to? :call
8
+ adm_registry_loader.call
9
+ elsif adm_registry
10
+ adm_registry
11
+ else
12
+ DEFAULT_DAO_REGISTRY_LOADER.call
13
+ end
14
+ end
15
+
16
+ # set_xxx* methods can be chained (return self)
17
+ # xxx= methods return the value set
18
+
19
+ def adm_registry
20
+ adm_registry_loader.call
21
+ end
22
+
23
+ def adm_registry_loader
24
+ @adm_registry_loader || DEFAULT_DAO_REGISTRY_LOADER
25
+ end
26
+
27
+ attr_writer :adm_registry_loader
28
+
29
+ def set_adm_registry_loader(adm_registry_loader)
30
+ self.adm_registry_loader = adm_registry_loader
31
+ self
32
+ end
33
+
34
+ def adm_registry=(adm_registry)
35
+ if adm_registry
36
+ set_adm_registry_loader ->() { adm_registry }
37
+ else
38
+ set_default_adm_registry_loader
39
+ end
40
+
41
+ adm_registry
42
+ end
43
+
44
+ def set_adm_registry(adm_registry)
45
+ self.adm_registry = adm_registry
46
+ self
47
+ end
48
+
49
+ def default_adm_registry
50
+ DEFAULT_DAO_REGISTRY_LOADER.call
51
+ end
52
+
53
+ def set_default_adm_registry_loader
54
+ @adm_registry_loader = nil
55
+ self
56
+ end
57
+
58
+ alias_method :set_default_adm_registry, :set_default_adm_registry_loader
59
+
60
+ # will use the loader if present, if not it will use the registry, if not present it will do nothing.
61
+ def set_adm_registry_and_loader(adm_registry_loader, adm_registry)
62
+ raise ArgumentError, 'loader has to respond to :call' if adm_registry_loader.present? && !adm_registry_loader.respond_to?(:call)
63
+
64
+ if adm_registry_loader.respond_to? :call
65
+ set_adm_registry_loader adm_registry_loader
66
+ elsif adm_registry
67
+ set_adm_registry adm_registry
68
+ end
69
+
70
+ self
71
+ end
72
+
73
+ end
@@ -16,7 +16,7 @@ require 'artirix_cache_service'
16
16
 
17
17
 
18
18
  # loading features
19
- require 'artirix_data_models/with_dao_registry'
19
+ require 'artirix_data_models/with_adm_registry'
20
20
  require 'artirix_data_models/inspectable'
21
21
  require 'artirix_data_models/es_collection'
22
22
  require 'artirix_data_models/aggregation'
@@ -35,7 +35,7 @@ require 'artirix_data_models/dao_concerns/with_response_adaptors'
35
35
  require 'artirix_data_models/dao'
36
36
  require 'artirix_data_models/daos/model_fields_dao'
37
37
  require 'artirix_data_models/daos/basic_model_dao'
38
- require 'artirix_data_models/dao_registry'
38
+ require 'artirix_data_models/adm_registry'
39
39
  require 'artirix_data_models/fake_response_factory'
40
40
  require 'artirix_data_models/active_null'
41
41
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe ArtirixDataModels::DAORegistry, type: :model do
3
+ RSpec.describe ArtirixDataModels::ADMRegistry, type: :model do
4
4
  Given(:subject) { described_class.instance }
5
5
 
6
6
  # common config mock
data/spec/spec_helper.rb CHANGED
@@ -2,8 +2,8 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'bundler/setup'
3
3
  Bundler.setup
4
4
 
5
- require 'codeclimate-test-reporter'
6
- CodeClimate::TestReporter.start
5
+ require 'simplecov'
6
+ SimpleCov.start
7
7
 
8
8
  require 'rspec/given'
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artirix_data_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -257,6 +257,7 @@ files:
257
257
  - bin/setup
258
258
  - lib/artirix_data_models.rb
259
259
  - lib/artirix_data_models/active_null.rb
260
+ - lib/artirix_data_models/adm_registry.rb
260
261
  - lib/artirix_data_models/aggregation.rb
261
262
  - lib/artirix_data_models/aggregation_builder.rb
262
263
  - lib/artirix_data_models/aggregations_factory.rb
@@ -267,7 +268,6 @@ files:
267
268
  - lib/artirix_data_models/cached_action_adaptor/get_some.rb
268
269
  - lib/artirix_data_models/dao.rb
269
270
  - lib/artirix_data_models/dao_concerns/with_response_adaptors.rb
270
- - lib/artirix_data_models/dao_registry.rb
271
271
  - lib/artirix_data_models/daos/basic_model_dao.rb
272
272
  - lib/artirix_data_models/daos/model_fields_dao.rb
273
273
  - lib/artirix_data_models/es_collection.rb
@@ -286,8 +286,8 @@ files:
286
286
  - lib/artirix_data_models/spec_support/shared_examples/an_artirix_data_model_model.rb
287
287
  - lib/artirix_data_models/spec_support/shared_examples/has_attributes.rb
288
288
  - lib/artirix_data_models/version.rb
289
- - lib/artirix_data_models/with_dao_registry.rb
290
- - spec/artirix_data_models/dao_registry_spec.rb
289
+ - lib/artirix_data_models/with_adm_registry.rb
290
+ - spec/artirix_data_models/adm_registry_spec.rb
291
291
  - spec/artirix_data_models/es_collection_spec.rb
292
292
  - spec/artirix_data_models/gateways/data_gateway_spec.rb
293
293
  - spec/artirix_data_models/gateways/gateway_response_adaptors/model_adaptor_spec.rb
@@ -321,9 +321,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
321
321
  version: '0'
322
322
  required_rubygems_version: !ruby/object:Gem::Requirement
323
323
  requirements:
324
- - - ">="
324
+ - - ">"
325
325
  - !ruby/object:Gem::Version
326
- version: '0'
326
+ version: 1.3.1
327
327
  requirements: []
328
328
  rubyforge_project:
329
329
  rubygems_version: 2.5.1
@@ -331,7 +331,7 @@ signing_key:
331
331
  specification_version: 4
332
332
  summary: Data Models (read only model) and Data Layer connection lib
333
333
  test_files:
334
- - spec/artirix_data_models/dao_registry_spec.rb
334
+ - spec/artirix_data_models/adm_registry_spec.rb
335
335
  - spec/artirix_data_models/es_collection_spec.rb
336
336
  - spec/artirix_data_models/gateways/data_gateway_spec.rb
337
337
  - spec/artirix_data_models/gateways/gateway_response_adaptors/model_adaptor_spec.rb
@@ -350,4 +350,3 @@ test_files:
350
350
  - spec/support/a_search_enabled_ui_model_dao.rb
351
351
  - spec/support/artirix_data_models.rb
352
352
  - spec/support/fixtures.rb
353
- has_rdoc:
@@ -1,73 +0,0 @@
1
- module ArtirixDataModels::WithDAORegistry
2
- DEFAULT_DAO_REGISTRY_LOADER = ->() { ArtirixDataModels::DAORegistry.instance }
3
-
4
- def self.loader_or_registry_or_default(dao_registry: nil, dao_registry_loader: nil)
5
- raise ArgumentError, 'loader has to respond to :call' if dao_registry_loader.present? && !dao_registry_loader.respond_to?(:call)
6
-
7
- if dao_registry_loader.respond_to? :call
8
- dao_registry_loader.call
9
- elsif dao_registry
10
- dao_registry
11
- else
12
- DEFAULT_DAO_REGISTRY_LOADER.call
13
- end
14
- end
15
-
16
- # set_xxx* methods can be chained (return self)
17
- # xxx= methods return the value set
18
-
19
- def dao_registry
20
- dao_registry_loader.call
21
- end
22
-
23
- def dao_registry_loader
24
- @dao_registry_loader || DEFAULT_DAO_REGISTRY_LOADER
25
- end
26
-
27
- attr_writer :dao_registry_loader
28
-
29
- def set_dao_registry_loader(dao_registry_loader)
30
- self.dao_registry_loader = dao_registry_loader
31
- self
32
- end
33
-
34
- def dao_registry=(dao_registry)
35
- if dao_registry
36
- set_dao_registry_loader ->() { dao_registry }
37
- else
38
- set_default_dao_registry_loader
39
- end
40
-
41
- dao_registry
42
- end
43
-
44
- def set_dao_registry(dao_registry)
45
- self.dao_registry = dao_registry
46
- self
47
- end
48
-
49
- def default_dao_registry
50
- DEFAULT_DAO_REGISTRY_LOADER.call
51
- end
52
-
53
- def set_default_dao_registry_loader
54
- @dao_registry_loader = nil
55
- self
56
- end
57
-
58
- alias_method :set_default_dao_registry, :set_default_dao_registry_loader
59
-
60
- # will use the loader if present, if not it will use the registry, if not present it will do nothing.
61
- def set_dao_registry_and_loader(dao_registry_loader, dao_registry)
62
- raise ArgumentError, 'loader has to respond to :call' if dao_registry_loader.present? && !dao_registry_loader.respond_to?(:call)
63
-
64
- if dao_registry_loader.respond_to? :call
65
- set_dao_registry_loader dao_registry_loader
66
- elsif dao_registry
67
- set_dao_registry dao_registry
68
- end
69
-
70
- self
71
- end
72
-
73
- end