artirix_data_models 1.0.0.beta1 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/README.md +81 -25
- data/lib/artirix_data_models/model.rb +50 -16
- data/lib/artirix_data_models/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b789a4325708b34bd7ebfdc7745857c0b15c274
|
4
|
+
data.tar.gz: a0b4df2ed3b9a82761ad7b7474d2456c7c1ec622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3067423501cef36002fc3c46a8d1bca73541ed2cfd92acb068b704472dca356d2c771f3e4434a554983dbe86f0b2956bcf181cf4d0554b8294c778572c1c6e4
|
7
|
+
data.tar.gz: d82ad3c5b183de485ddd6c3d85b749fe03abb5b5ba3dbd9c8c3ed9c3ad1918338fca8d08eb6e22efa000d8ac1fdd1ac4885fb9357d4dd48f393e7d40f8bcd242
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -15,11 +15,6 @@ Its goal is to provide a set of Read Only model objects that receive their data
|
|
15
15
|
|
16
16
|
It's designed to work assuming JSON APIs and ElasticSearch responses.
|
17
17
|
|
18
|
-
# TODO:
|
19
|
-
- usage doc
|
20
|
-
- change Cache to use [artirix_cache_service](https://github.com/artirix/artirix_cache_service)
|
21
|
-
|
22
|
-
|
23
18
|
note: for making a model compatible with [ActiveModelSerializers](https://github.com/rails-api/active_model_serializers), use [artirix_data_models-ams](https://github.com/artirix/artirix_data_models-ams/)
|
24
19
|
|
25
20
|
## Usage
|
@@ -321,11 +316,73 @@ end
|
|
321
316
|
|
322
317
|
1. Documentation
|
323
318
|
2. clean `basic_dao` (probably not backwards compatible, so we'll do it in a new major release)
|
324
|
-
3.
|
319
|
+
3. config flags to modify the composition of Model (ie: include/exclude partial mode behaviour, default attributes...)
|
325
320
|
|
321
|
+
## Changes
|
326
322
|
|
323
|
+
### 1.0.0.beta2
|
327
324
|
|
328
|
-
|
325
|
+
- Partial Mode: the default mode status is inherited from the parent class. If you have
|
326
|
+
|
327
|
+
```ruby
|
328
|
+
class A
|
329
|
+
include ArtirixDataModels::Model
|
330
|
+
self.mark_full_mode_by_default
|
331
|
+
end
|
332
|
+
|
333
|
+
class B < A
|
334
|
+
end
|
335
|
+
|
336
|
+
class C
|
337
|
+
include ArtirixDataModels::Model
|
338
|
+
end
|
339
|
+
|
340
|
+
A.default_full_mode? # => true
|
341
|
+
B.default_full_mode? # => true (it would be false before this version)
|
342
|
+
C.default_full_mode? # => false
|
343
|
+
```
|
344
|
+
|
345
|
+
- Default Mode: you can override the default mode (if not overridden it will be `:partial`)
|
346
|
+
```ruby
|
347
|
+
|
348
|
+
# make it full mode by default
|
349
|
+
config.x.artirix_data_models.default_mode = :full
|
350
|
+
```
|
351
|
+
|
352
|
+
|
353
|
+
- Default Attributes: you can override the list of default attributes
|
354
|
+
```ruby
|
355
|
+
|
356
|
+
# add no default attributes
|
357
|
+
config.x.artirix_data_models.default_attributes = []
|
358
|
+
|
359
|
+
# only _timestamp
|
360
|
+
config.x.artirix_data_models.default_attributes = [:_timestamp]
|
361
|
+
|
362
|
+
# if nothing is specified in the config, the default attributes are:
|
363
|
+
[
|
364
|
+
:_timestamp,
|
365
|
+
:_score,
|
366
|
+
:_type,
|
367
|
+
:_index,
|
368
|
+
:_id,
|
369
|
+
]
|
370
|
+
```
|
371
|
+
|
372
|
+
- Default Attributes always in Partial Mode: you can override the list of attributes always in partial mode
|
373
|
+
```ruby
|
374
|
+
|
375
|
+
# add no default attributes
|
376
|
+
config.x.artirix_data_models.attributes_always_in_partial_mode = []
|
377
|
+
|
378
|
+
# _timestamp and _score
|
379
|
+
config.x.artirix_data_models.attributes_always_in_partial_mode = [:_timestamp, :_score]
|
380
|
+
|
381
|
+
# if nothing is specified in the config, the default attributes are:
|
382
|
+
[
|
383
|
+
:_timestamp,
|
384
|
+
]
|
385
|
+
```
|
329
386
|
|
330
387
|
### Breaking Changes!!: version 1.0.0.beta1
|
331
388
|
|
@@ -391,7 +448,7 @@ added message support for DataGateway exceptions
|
|
391
448
|
|
392
449
|
### 0.22.0
|
393
450
|
|
394
|
-
added support for aggregations that look like
|
451
|
+
added support for aggregations that look like
|
395
452
|
```json
|
396
453
|
{
|
397
454
|
"aggregations": {
|
@@ -421,8 +478,8 @@ which will be added as an aggregation like:
|
|
421
478
|
|
422
479
|
```ruby
|
423
480
|
es_collection.aggregations.first.name # => :published_states
|
424
|
-
es_collection.aggregations.first.buckets
|
425
|
-
# => [
|
481
|
+
es_collection.aggregations.first.buckets
|
482
|
+
# => [
|
426
483
|
# {name: 'live_soon', count: 0},
|
427
484
|
# {name: 'draft', count: 3},
|
428
485
|
# {name: 'expired', count: 0},
|
@@ -432,13 +489,13 @@ es_collection.aggregations.first.buckets
|
|
432
489
|
|
433
490
|
### 0.21.1
|
434
491
|
|
435
|
-
Fix bug in `Inspectable`, on Arrays.
|
492
|
+
Fix bug in `Inspectable`, on Arrays.
|
436
493
|
|
437
494
|
### 0.21.0
|
438
495
|
|
439
|
-
Changed cache to use `ArtirixCacheService` (gem `artirix_cache_service`).
|
496
|
+
Changed cache to use `ArtirixCacheService` (gem `artirix_cache_service`).
|
440
497
|
|
441
|
-
Deprecated the use of method_missing on cache in favour of the `.key` method:
|
498
|
+
Deprecated the use of method_missing on cache in favour of the `.key` method:
|
442
499
|
|
443
500
|
```ruby
|
444
501
|
# this is deprecated
|
@@ -460,7 +517,7 @@ ArtirixDataModels::CacheService.first_options 'some', 'other', return_if_missing
|
|
460
517
|
|
461
518
|
|
462
519
|
### 0.20.0
|
463
|
-
Added `ensure_relative` boolean option to the creation of a `DataGateway` (disable by default). With it enabled, it will ensure that any given `path` is relative by removing the leading `/`. This is necessary if the Gateway should call a nested endpoint and not just a host.
|
520
|
+
Added `ensure_relative` boolean option to the creation of a `DataGateway` (disable by default). With it enabled, it will ensure that any given `path` is relative by removing the leading `/`. This is necessary if the Gateway should call a nested endpoint and not just a host.
|
464
521
|
|
465
522
|
Example: If we have `"http://example.org/api/"` as connection's URL, and path `"/people/1"`, with this:
|
466
523
|
|
@@ -481,7 +538,7 @@ Added `configuration_loader` and support for `Rails.configuration.x.artirix_data
|
|
481
538
|
`DataGateway` connection loader now moved to `DataGateway::ConnectionLoader`, with 3 public methods:
|
482
539
|
- `default_connection` which will give us the connection based on config in `data_gateway` group in `SimpleConfig.for(:site)`
|
483
540
|
- `connection_by_config_key(config_key)` which will give us the connection based on config in the given group key in `SimpleConfig.for(:site)`
|
484
|
-
- `connection(config: {}, url: nil, login: nil, password: nil, bearer_token: nil, token_hash: nil)`: It will use the elements from the given config if they are not present on the params.
|
541
|
+
- `connection(config: {}, url: nil, login: nil, password: nil, bearer_token: nil, token_hash: nil)`: It will use the elements from the given config if they are not present on the params.
|
485
542
|
|
486
543
|
### 0.17.0
|
487
544
|
|
@@ -519,7 +576,7 @@ updating dependencies: KeywordInit (to support passing nil)
|
|
519
576
|
- `Gateway` `perform` and `connect` now accept the extra arguments as keyword arguments:
|
520
577
|
|
521
578
|
```ruby
|
522
|
-
gateway.perform :get, path: '/this/is/required' body: nil, json_body: true, timeout: 10
|
579
|
+
gateway.perform :get, path: '/this/is/required' body: nil, json_body: true, timeout: 10
|
523
580
|
```
|
524
581
|
|
525
582
|
The internals are adapted but if a client app was mocking Gateway's `perform` directly, this could be a breaking change.
|
@@ -539,7 +596,7 @@ end
|
|
539
596
|
|
540
597
|
### 0.14.1
|
541
598
|
- Exceptions now with `data_hash` and ability to be raised with message, options, or both.
|
542
|
-
- Cache Adaptors now store the data hash of the NotFound exception, and a new one is built and raised when reading a cached NotFound.
|
599
|
+
- Cache Adaptors now store the data hash of the NotFound exception, and a new one is built and raised when reading a cached NotFound.
|
543
600
|
|
544
601
|
```ruby
|
545
602
|
raise ArtirixDataModels::DataGateway::NotFound, 'blah blah'
|
@@ -555,7 +612,7 @@ raise ArtirixDataModels::DataGateway::NotFound.new('Something', path: 'x')
|
|
555
612
|
```ruby
|
556
613
|
class MyModel
|
557
614
|
include ArtirixDataModels::Model
|
558
|
-
|
615
|
+
|
559
616
|
mark_full_mode_by_default
|
560
617
|
end
|
561
618
|
|
@@ -589,7 +646,7 @@ x.full_mode? # => true
|
|
589
646
|
- Gateways:
|
590
647
|
-- 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.
|
591
648
|
-- `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).
|
592
|
-
-- `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.
|
649
|
+
-- `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.
|
593
650
|
|
594
651
|
- Response Adaptors
|
595
652
|
-- `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.
|
@@ -610,9 +667,9 @@ x.full_mode? # => true
|
|
610
667
|
- Fake Responses now can be a callable object (if it responds to `call` it will invoke it)
|
611
668
|
- refactor in `ArtirixDataModels::DataGateway` to add more info into the exceptions
|
612
669
|
- `ArtirixDataModels::DataGateway::Error` and subclasses have now `path`, `method`, `response_status`, `response_body` (when applicable) and also `json_response_body` method which will try to parse `response_body` as if it were json (nil if it is not present or if it is not a valid json)
|
613
|
-
- `ArtirixDataModels::DataGateway::Error` subclasses now for specific response status:
|
670
|
+
- `ArtirixDataModels::DataGateway::Error` subclasses now for specific response status:
|
614
671
|
-- `NotFound`
|
615
|
-
-- `NotAcceptable`
|
672
|
+
-- `NotAcceptable`
|
616
673
|
-- `UnprocessableEntity`
|
617
674
|
-- `Unauthorized`
|
618
675
|
-- `Forbidden`
|
@@ -654,7 +711,7 @@ Yanked because of the gateway mock helpers were missing an option, which made th
|
|
654
711
|
- added `MetricAggregation`. Normal `AggregationBuilder` will build an aggregation with that class if instead of `buckets` it finds `value` in the JSON.
|
655
712
|
- normalize raw aggregations now does not ignore metric aggregations (see above)
|
656
713
|
- added `calculate_filtered(filtered_values)` to aggregations (noop in Metric aggregations). In a bucket aggregation, will mark with `filtered?` each bucket (aka Aggregation Value) if the `bucket.name` is present in the given `filtered_values`.
|
657
|
-
- added to `Aggregation` the methods:
|
714
|
+
- added to `Aggregation` the methods:
|
658
715
|
-- `filtered_buckets` that will return only buckets marked as `filtered?`
|
659
716
|
-- `unfiltered_buckets` that will return only buckets not marked as `filtered?`
|
660
717
|
-- `filtered_first_buckets` that will concatenate `filtered_buckets` and `unfiltered_buckets`
|
@@ -663,7 +720,7 @@ Yanked because of the gateway mock helpers were missing an option, which made th
|
|
663
720
|
|
664
721
|
### ~0.7.0~ (YANKED)
|
665
722
|
|
666
|
-
Yanked because of bug on Aggregations. Released 0.7.1 with the fix. Changeset moved too to 0.7.1
|
723
|
+
Yanked because of bug on Aggregations. Released 0.7.1 with the fix. Changeset moved too to 0.7.1
|
667
724
|
|
668
725
|
### 0.6.7
|
669
726
|
|
@@ -675,7 +732,7 @@ Yanked because of bug on Aggregations. Released 0.7.1 with the fix. Changeset mo
|
|
675
732
|
|
676
733
|
### 0.6.5
|
677
734
|
|
678
|
-
- Specify `activemodel` as a dependency and require it in the lib
|
735
|
+
- Specify `activemodel` as a dependency and require it in the lib
|
679
736
|
- `EsCollection` delegates `[]`, `first`, `last`, `take` and `drop` to the results.
|
680
737
|
|
681
738
|
|
@@ -719,4 +776,3 @@ Yanked because of breaking change introduction: removal of `Aggregation.from_jso
|
|
719
776
|
|
720
777
|
- opening gem as is to the public.
|
721
778
|
- still a lot of TODOs in the documentation
|
722
|
-
|
@@ -224,8 +224,8 @@ module ArtirixDataModels
|
|
224
224
|
return nil if skip_option.include?(:reader) || skip_option.include?(:getter)
|
225
225
|
|
226
226
|
variable_name = "@#{attribute}"
|
227
|
-
dir_get_name
|
228
|
-
reader
|
227
|
+
dir_get_name = Attributes.direct_getter_method_name(attribute)
|
228
|
+
reader = attribute.to_s
|
229
229
|
|
230
230
|
define_method dir_get_name do
|
231
231
|
instance_variable_get variable_name
|
@@ -268,14 +268,34 @@ module ArtirixDataModels
|
|
268
268
|
module WithDefaultAttributes
|
269
269
|
extend ActiveSupport::Concern
|
270
270
|
|
271
|
+
DEFAULT_ATTRIBUTES = [
|
272
|
+
:_timestamp,
|
273
|
+
:_score,
|
274
|
+
:_type,
|
275
|
+
:_index,
|
276
|
+
:_id,
|
277
|
+
].freeze
|
278
|
+
|
279
|
+
ATTRIBUTES_ALWAYS_IN_PARTIAL_MODE = [
|
280
|
+
:_timestamp,
|
281
|
+
].freeze
|
282
|
+
|
271
283
|
included do
|
272
|
-
|
273
|
-
|
284
|
+
WithDefaultAttributes.default_attribute_names.each do |at|
|
285
|
+
attribute at
|
286
|
+
end
|
287
|
+
|
288
|
+
WithDefaultAttributes.default_attributes_always_in_partial_mode.each do |at|
|
289
|
+
always_in_partial_mode(at) if respond_to?(:always_in_partial_mode)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def self.default_attribute_names
|
294
|
+
Array(ArtirixDataModels.configuration.try(:default_attributes) || DEFAULT_ATTRIBUTES)
|
295
|
+
end
|
274
296
|
|
275
|
-
|
276
|
-
|
277
|
-
attribute :_index
|
278
|
-
attribute :_id
|
297
|
+
def self.default_attributes_always_in_partial_mode
|
298
|
+
Array(ArtirixDataModels.configuration.try(:attributes_always_in_partial_mode) || ATTRIBUTES_ALWAYS_IN_PARTIAL_MODE)
|
279
299
|
end
|
280
300
|
end
|
281
301
|
end
|
@@ -364,7 +384,7 @@ module ArtirixDataModels
|
|
364
384
|
extend ActiveSupport::Concern
|
365
385
|
|
366
386
|
EMPTY_TIMESTAMP = 'no_time'.freeze
|
367
|
-
SEPARATOR
|
387
|
+
SEPARATOR = '/'.freeze
|
368
388
|
|
369
389
|
def cache_key
|
370
390
|
# we do not want to force a reload for loading the cache key, it can lead to an infinite loop
|
@@ -468,28 +488,42 @@ module ArtirixDataModels
|
|
468
488
|
end
|
469
489
|
|
470
490
|
def default_full_mode?
|
471
|
-
|
491
|
+
attribute_config.default_mode == :full
|
472
492
|
end
|
473
493
|
|
474
494
|
def mark_full_mode_by_default
|
475
|
-
attribute_config.
|
495
|
+
attribute_config.default_mode = :full
|
476
496
|
end
|
477
497
|
|
478
498
|
def mark_partial_mode_by_default
|
479
|
-
attribute_config.
|
499
|
+
attribute_config.default_mode = :partial
|
500
|
+
end
|
501
|
+
|
502
|
+
def restore_default_mode
|
503
|
+
attribute_config.default_mode = nil
|
480
504
|
end
|
481
505
|
end
|
482
506
|
end
|
483
507
|
|
484
508
|
class AttributeConfig
|
485
509
|
attr_reader :attribute_list, :always_in_partial_mode_list
|
486
|
-
attr_accessor :parent_attribute_config
|
510
|
+
attr_accessor :parent_attribute_config
|
511
|
+
attr_writer :default_mode
|
487
512
|
|
488
513
|
def initialize
|
489
|
-
@attribute_list
|
514
|
+
@attribute_list = Set.new
|
490
515
|
@always_in_partial_mode_list = Set.new
|
491
|
-
@parent_attribute_config
|
492
|
-
@
|
516
|
+
@parent_attribute_config = nil
|
517
|
+
@default_mode = nil
|
518
|
+
end
|
519
|
+
|
520
|
+
def default_mode
|
521
|
+
return @default_mode unless @default_mode.nil?
|
522
|
+
parent_attribute_config.try(:default_mode) || initial_default_mode
|
523
|
+
end
|
524
|
+
|
525
|
+
def initial_default_mode
|
526
|
+
ArtirixDataModels.configuration.try(:default_mode) || :partial
|
493
527
|
end
|
494
528
|
|
495
529
|
def attributes
|
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: 1.0.0.
|
4
|
+
version: 1.0.0.beta2
|
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:
|
11
|
+
date: 2017-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|