artirix_data_models 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/lib/artirix_data_models/dao.rb +17 -8
- data/lib/artirix_data_models/daos/basic_model_dao.rb +53 -23
- data/lib/artirix_data_models/gateways/data_gateway.rb +25 -7
- data/lib/artirix_data_models/model.rb +13 -0
- data/lib/artirix_data_models/version.rb +1 -1
- data/lib/artirix_data_models.rb +3 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f52a06bf80abd71040a8661490da1421091e39b7
|
4
|
+
data.tar.gz: 37fc26419d9f609a85a4911d80914e10d17193d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f73b885df6a65abca53fd08529c044d08b0bdfcd11158bc36ef447dda3e9b2c70acc72a3a2cff9d39b9c16701b7fdca98b15597882535c1e98f1a232a49a23a
|
7
|
+
data.tar.gz: a6bbe32acdb54513ae625e60ef36b6c60276a7e46724be2af0f3e08dd20f61fedea33a09f58f2539c6449919b6f0426b951b990f8330cd405dbd6c51df7161d5
|
data/README.md
CHANGED
@@ -250,6 +250,27 @@ end
|
|
250
250
|
|
251
251
|
## Changes
|
252
252
|
|
253
|
+
### 0.10.0
|
254
|
+
|
255
|
+
- Gateways:
|
256
|
+
-- added `gateway_factory` besides `gateway` as a creation argument for a DAO and BasicModelDAO. Now, when using a gateway in BasicModelDAO, it will use the given gateway if present, or it will call `gateway_factory.call` and use it. It won't save the result of the gateway factory, so the factory will be called every time a gateway is used.
|
257
|
+
-- `BasicModelDAO` methods can receive a `gateway` option to be used instead of the normal gateway for the particular request. Used in `_get`, `_post`, `_put` and `_delete` methods. If no override is passed, then it will use the preloaded gateway (using either `gateway` or `gateway_factory` creation arguments, see above).
|
258
|
+
-- `DAO` creation accepts an option `ignore_default_gateway` (`false` by default). If it is false, and no `gateway` or `gateway_factory` is passed, the gateway used will be `DAORegistry.gateway` (same as before). This allows to create DAOs without any gateway configured, making it necessary to instantiate it and pass it to `BasicModelDAO` on each request.
|
259
|
+
|
260
|
+
- Response Adaptors
|
261
|
+
-- `DAO`'s `get_full` method now can pass to `BasicModelDAO` a `response_adaptor` option. `BasicModelDAO` will use `BasicModelDAO`'s `response_adaptor_for_reload` if no response adaptor is passed.
|
262
|
+
-- `DAO`'s `find` and `get` methods now can pass to `BasicModelDAO` a `response_adaptor` option. `BasicModelDAO` will use `BasicModelDAO`'s `response_adaptor_for_single` if no response adaptor is passed.
|
263
|
+
-- `DAO`'s `find` and `get_some` methods now can pass to `BasicModelDAO` a `response_adaptor` option. `BasicModelDAO` will use `BasicModelDAO`'s `response_adaptor_for_some` if no response adaptor is passed.
|
264
|
+
|
265
|
+
- `DAO`s now delegate `model_adaptor_factory` to `BasicModelDAO`
|
266
|
+
- created `IllegalActionError` error class inside of `ArtirixDataModels` module
|
267
|
+
|
268
|
+
- `ArtirixDataModels::Model` with another module `WithoutDefaultAttributes`, same as `CompleteModel` but without default attributes.
|
269
|
+
|
270
|
+
- `ArtirixDataModels::DataGateway::Error` subclass now for status `409`: `Conflict`
|
271
|
+
|
272
|
+
- in `ArtirixDataModels::DataGateway`, methods `treat_response` and `exception_for_status` are now static. They can still be used in an instance level (it delegates to class methods)
|
273
|
+
|
253
274
|
### 0.9.0
|
254
275
|
|
255
276
|
- Fake Responses now can be a callable object (if it responds to `call` it will invoke it)
|
@@ -17,6 +17,7 @@ module ArtirixDataModels
|
|
17
17
|
:forced_fake_disabled?,
|
18
18
|
:empty_collection,
|
19
19
|
:empty_collection_for,
|
20
|
+
:model_adaptor_factory
|
20
21
|
]
|
21
22
|
|
22
23
|
included do
|
@@ -25,13 +26,21 @@ module ArtirixDataModels
|
|
25
26
|
end
|
26
27
|
|
27
28
|
|
28
|
-
def initialize(gateway: nil, model_name: nil, model_class: nil, paths_factory: nil, fake_mode_factory: nil)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def initialize(gateway: nil, gateway_factory: nil, ignore_default_gateway: false, model_name: nil, model_class: nil, paths_factory: nil, fake_mode_factory: nil)
|
30
|
+
if gateway.blank? && gateway_factory.blank? && !ignore_default_gateway
|
31
|
+
gateway = ArtirixDataModels::DAORegistry.gateway
|
32
|
+
end
|
33
|
+
|
34
|
+
model_name ||= default_model_name
|
35
|
+
model_class ||= default_model_class
|
36
|
+
paths_factory ||= default_path_factory
|
37
|
+
fake_mode_factory ||= default_fake_mode_factory
|
38
|
+
@basic_model_dao = ArtirixDataModels::DAORegistry.basic_class.new model_name: model_name,
|
39
|
+
model_class: model_class,
|
40
|
+
fake_mode_factory: fake_mode_factory,
|
41
|
+
paths_factory: paths_factory,
|
42
|
+
gateway: gateway,
|
43
|
+
gateway_factory: gateway_factory
|
35
44
|
end
|
36
45
|
|
37
46
|
def default_model_name
|
@@ -75,7 +84,7 @@ module ArtirixDataModels
|
|
75
84
|
|
76
85
|
def get_full(model_pk, model_to_reload: nil, cache_adaptor: nil, **extra_options)
|
77
86
|
model_to_reload ||= new_model_with_pk(model_pk)
|
78
|
-
cache_adaptor
|
87
|
+
cache_adaptor ||= cache_model_adaptor_for_get_full(model_pk, model_to_reload: model_to_reload, **extra_options)
|
79
88
|
basic_model_dao.get_full(model_pk, model_to_reload: model_to_reload, cache_adaptor: cache_adaptor, **extra_options)
|
80
89
|
end
|
81
90
|
|
@@ -1,14 +1,21 @@
|
|
1
1
|
class ArtirixDataModels::BasicModelDAO
|
2
|
-
attr_reader :model_name, :model_class, :paths_factory, :
|
2
|
+
attr_reader :model_name, :model_class, :paths_factory, :fake_mode_factory, :gateway_factory, :loaded_gateway
|
3
3
|
|
4
|
-
def initialize(model_name
|
4
|
+
def initialize(model_name:, model_class:, paths_factory:, gateway:, fake_mode_factory:, gateway_factory:)
|
5
5
|
@model_name = model_name
|
6
6
|
@model_class = model_class
|
7
7
|
@paths_factory = paths_factory
|
8
|
-
@
|
8
|
+
@loaded_gateway = gateway
|
9
|
+
@gateway_factory = gateway_factory
|
9
10
|
@fake_mode_factory = fake_mode_factory
|
10
11
|
end
|
11
12
|
|
13
|
+
def preloaded_gateway
|
14
|
+
loaded_gateway.presence || gateway_factory.call
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :gateway, :preloaded_gateway
|
18
|
+
|
12
19
|
def partial_mode_fields
|
13
20
|
if fake?
|
14
21
|
fake_mode_factory.partial_mode_fields
|
@@ -17,11 +24,11 @@ class ArtirixDataModels::BasicModelDAO
|
|
17
24
|
end
|
18
25
|
end
|
19
26
|
|
20
|
-
def get_full(model_pk, model_to_reload:, cache_adaptor: nil, **extra_options)
|
21
|
-
path
|
22
|
-
|
27
|
+
def get_full(model_pk, model_to_reload:, response_adaptor: nil, cache_adaptor: nil, **extra_options)
|
28
|
+
path = paths_factory.get_full model_pk
|
29
|
+
response_adaptor ||= response_adaptor_for_reload(model_to_reload)
|
23
30
|
|
24
|
-
_get path, response_adaptor:
|
31
|
+
_get path, response_adaptor: response_adaptor, fake_response: fake_get_full_response(model_pk, model_to_reload), cache_adaptor: cache_adaptor, **extra_options
|
25
32
|
|
26
33
|
model_to_reload.mark_full_mode
|
27
34
|
model_to_reload
|
@@ -33,18 +40,18 @@ class ArtirixDataModels::BasicModelDAO
|
|
33
40
|
nil
|
34
41
|
end
|
35
42
|
|
36
|
-
def find(model_pk, cache_adaptor: nil, **extra_options)
|
37
|
-
path
|
38
|
-
|
43
|
+
def find(model_pk, cache_adaptor: nil, response_adaptor: nil, **extra_options)
|
44
|
+
path = paths_factory.get model_pk
|
45
|
+
response_adaptor ||= response_adaptor_for_single
|
39
46
|
|
40
|
-
_get(path, response_adaptor:
|
47
|
+
_get(path, response_adaptor: response_adaptor, fake_response: fake_get_response(model_pk), cache_adaptor: cache_adaptor, **extra_options)
|
41
48
|
end
|
42
49
|
|
43
|
-
def get_some(model_pks, cache_adaptor: nil, **extra_options)
|
44
|
-
path
|
45
|
-
|
50
|
+
def get_some(model_pks, cache_adaptor: nil, response_adaptor: nil, **extra_options)
|
51
|
+
path = paths_factory.get_some(model_pks)
|
52
|
+
response_adaptor ||= response_adaptor_for_some
|
46
53
|
|
47
|
-
_get(path, response_adaptor:
|
54
|
+
_get(path, response_adaptor: response_adaptor, fake_response: fake_get_some_response(model_pks), cache_adaptor: cache_adaptor, **extra_options)
|
48
55
|
rescue ArtirixDataModels::DataGateway::NotFound
|
49
56
|
[]
|
50
57
|
end
|
@@ -116,20 +123,28 @@ class ArtirixDataModels::BasicModelDAO
|
|
116
123
|
ArtirixDataModels::GatewayResponseAdaptors::ModelAdaptor
|
117
124
|
end
|
118
125
|
|
119
|
-
def _get(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil)
|
120
|
-
gateway.
|
126
|
+
def _get(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
127
|
+
g = gateway.presence || preloaded_gateway
|
128
|
+
raise_no_gateway unless g.present?
|
129
|
+
g.get path, response_adaptor: response_adaptor, body: body, fake: fake?, fake_response: fake_response, cache_adaptor: cache_adaptor
|
121
130
|
end
|
122
131
|
|
123
|
-
def _post(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil)
|
124
|
-
gateway.
|
132
|
+
def _post(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
133
|
+
g = gateway.presence || preloaded_gateway
|
134
|
+
raise_no_gateway unless g.present?
|
135
|
+
g.post path, response_adaptor: response_adaptor, body: body, fake: fake?, fake_response: fake_response, cache_adaptor: cache_adaptor
|
125
136
|
end
|
126
137
|
|
127
|
-
def _put(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil)
|
128
|
-
gateway.
|
138
|
+
def _put(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
139
|
+
g = gateway.presence || preloaded_gateway
|
140
|
+
raise_no_gateway unless g.present?
|
141
|
+
g.put path, response_adaptor: response_adaptor, body: body, fake: fake?, fake_response: fake_response, cache_adaptor: cache_adaptor
|
129
142
|
end
|
130
143
|
|
131
|
-
def _delete(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil)
|
132
|
-
gateway.
|
144
|
+
def _delete(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
145
|
+
g = gateway.presence || preloaded_gateway
|
146
|
+
raise_no_gateway unless g.present?
|
147
|
+
g.delete path, response_adaptor: response_adaptor, body: body, fake: fake?, fake_response: fake_response, cache_adaptor: cache_adaptor
|
133
148
|
end
|
134
149
|
|
135
150
|
def fake?
|
@@ -137,4 +152,19 @@ class ArtirixDataModels::BasicModelDAO
|
|
137
152
|
return false if forced_fake_disabled?
|
138
153
|
fake_mode_factory.enabled?
|
139
154
|
end
|
155
|
+
|
156
|
+
def raise_no_gateway
|
157
|
+
msg = 'no gateway passed to request, no gateway configured on creation'
|
158
|
+
if gateway_factory.present?
|
159
|
+
msg = "#{msg}, and no gateway returned by the factory"
|
160
|
+
else
|
161
|
+
msg = "#{msg}, and no gateway factory configured on creation"
|
162
|
+
end
|
163
|
+
|
164
|
+
raise NoGatewayConfiguredError, msg
|
165
|
+
end
|
166
|
+
|
167
|
+
class NoGatewayConfiguredError < StandardError
|
168
|
+
end
|
169
|
+
|
140
170
|
end
|
@@ -77,13 +77,6 @@ class ArtirixDataModels::DataGateway
|
|
77
77
|
raise ConnectionError.new(path: path, method: method), "method: #{method}, path: #{path}, error: #{e}"
|
78
78
|
end
|
79
79
|
|
80
|
-
def treat_response(response, method, path)
|
81
|
-
return response.body if response.success?
|
82
|
-
|
83
|
-
klass = exception_for_status(response.status)
|
84
|
-
raise klass.new(path: path, method: method, response_body: response.body, response_status: response.status)
|
85
|
-
end
|
86
|
-
|
87
80
|
def body_to_json(body)
|
88
81
|
case body
|
89
82
|
when String
|
@@ -110,7 +103,26 @@ class ArtirixDataModels::DataGateway
|
|
110
103
|
raise ParseError.new(path: path, method: method, response_body: result), e.message
|
111
104
|
end
|
112
105
|
|
106
|
+
#######################
|
107
|
+
# EXCEPTION TREATMENT #
|
108
|
+
#######################
|
109
|
+
|
110
|
+
def treat_response(response, method, path)
|
111
|
+
self.class.treat_response(response, method, path)
|
112
|
+
end
|
113
|
+
|
113
114
|
def exception_for_status(response_status)
|
115
|
+
self.class.exception_for_status(response_status)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.treat_response(response, method, path)
|
119
|
+
return response.body if response.success?
|
120
|
+
|
121
|
+
klass = exception_for_status(response.status)
|
122
|
+
raise klass.new(path: path, method: method, response_body: response.body, response_status: response.status)
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.exception_for_status(response_status)
|
114
126
|
case response_status.to_i
|
115
127
|
when 404
|
116
128
|
NotFound
|
@@ -118,6 +130,8 @@ class ArtirixDataModels::DataGateway
|
|
118
130
|
NotAcceptable
|
119
131
|
when 422
|
120
132
|
UnprocessableEntity
|
133
|
+
when 409
|
134
|
+
Conflict
|
121
135
|
when 401
|
122
136
|
Unauthorized
|
123
137
|
when 403
|
@@ -223,6 +237,10 @@ class ArtirixDataModels::DataGateway
|
|
223
237
|
class UnprocessableEntity < Error
|
224
238
|
end
|
225
239
|
|
240
|
+
# 409
|
241
|
+
class Conflict < Error
|
242
|
+
end
|
243
|
+
|
226
244
|
##############################
|
227
245
|
# subclasses of GatewayError #
|
228
246
|
##############################
|
@@ -25,6 +25,19 @@ module ArtirixDataModels
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
module WithoutDefaultAttributes
|
29
|
+
extend ActiveSupport::Concern
|
30
|
+
|
31
|
+
included do
|
32
|
+
include ActiveModelCompliant
|
33
|
+
include Attributes
|
34
|
+
include PrimaryKey
|
35
|
+
include WithDAO
|
36
|
+
include CacheKey
|
37
|
+
include PartialMode
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
28
41
|
module CompleteModel
|
29
42
|
extend ActiveSupport::Concern
|
30
43
|
|
data/lib/artirix_data_models.rb
CHANGED
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.
|
4
|
+
version: 0.10.0
|
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
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -304,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
304
304
|
version: '0'
|
305
305
|
requirements: []
|
306
306
|
rubyforge_project:
|
307
|
-
rubygems_version: 2.2.
|
307
|
+
rubygems_version: 2.2.5
|
308
308
|
signing_key:
|
309
309
|
specification_version: 4
|
310
310
|
summary: Data Models (read only model) and Data Layer connection lib
|