ecoportal-api-v2 2.0.12 → 2.0.15

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/CHANGELOG.md +29 -3
  4. data/ecoportal-api-v2.gemspec +1 -1
  5. data/lib/ecoportal/api/common/content/array_model.rb +20 -3
  6. data/lib/ecoportal/api/common/content/class_helpers.rb +4 -2
  7. data/lib/ecoportal/api/common/content/client.rb +12 -6
  8. data/lib/ecoportal/api/common/content/collection_model/doc/items.rb +33 -0
  9. data/lib/ecoportal/api/common/content/collection_model/doc/rooted_key.rb +68 -0
  10. data/lib/ecoportal/api/common/content/collection_model/doc.rb +25 -0
  11. data/lib/ecoportal/api/common/content/collection_model/doc_mutation/delete.rb +33 -0
  12. data/lib/ecoportal/api/common/content/collection_model/doc_mutation/position.rb +42 -0
  13. data/lib/ecoportal/api/common/content/collection_model/doc_mutation/upsert.rb +45 -0
  14. data/lib/ecoportal/api/common/content/collection_model/doc_mutation.rb +27 -0
  15. data/lib/ecoportal/api/common/content/collection_model/model/cache.rb +44 -0
  16. data/lib/ecoportal/api/common/content/collection_model/model/items.rb +43 -0
  17. data/lib/ecoportal/api/common/content/collection_model/model/iterable.rb +44 -0
  18. data/lib/ecoportal/api/common/content/collection_model/model/lookup.rb +45 -0
  19. data/lib/ecoportal/api/common/content/collection_model/model/numeric_key.rb +40 -0
  20. data/lib/ecoportal/api/common/content/collection_model/model/var_tracking.rb +50 -0
  21. data/lib/ecoportal/api/common/content/collection_model/model.rb +33 -0
  22. data/lib/ecoportal/api/common/content/collection_model/modifiers/items_key.rb +57 -0
  23. data/lib/ecoportal/api/common/content/collection_model/modifiers/items_klass.rb +144 -0
  24. data/lib/ecoportal/api/common/content/collection_model/modifiers/items_order.rb +38 -0
  25. data/lib/ecoportal/api/common/content/collection_model/modifiers.rb +27 -0
  26. data/lib/ecoportal/api/common/content/collection_model/mutation/clear.rb +30 -0
  27. data/lib/ecoportal/api/common/content/collection_model/mutation/delete.rb +42 -0
  28. data/lib/ecoportal/api/common/content/collection_model/mutation/upsert.rb +56 -0
  29. data/lib/ecoportal/api/common/content/collection_model/mutation.rb +27 -0
  30. data/lib/ecoportal/api/common/content/collection_model.rb +19 -351
  31. data/lib/ecoportal/api/common/content/doc_helpers.rb +18 -16
  32. data/lib/ecoportal/api/common/content/double_model/attributable/base.rb +23 -0
  33. data/lib/ecoportal/api/common/content/double_model/attributable/enforce.rb +62 -0
  34. data/lib/ecoportal/api/common/content/double_model/attributable/nesting/cascaded_callback.rb +104 -0
  35. data/lib/ecoportal/api/common/content/double_model/attributable/nesting/embeddable.rb +76 -0
  36. data/lib/ecoportal/api/common/content/double_model/attributable/nesting/keyable.rb +119 -0
  37. data/lib/ecoportal/api/common/content/double_model/attributable/nesting.rb +136 -0
  38. data/lib/ecoportal/api/common/content/double_model/attributable/passthrough.rb +70 -0
  39. data/lib/ecoportal/api/common/content/double_model/attributable/simple.rb +48 -0
  40. data/lib/ecoportal/api/common/content/double_model/attributable.rb +30 -0
  41. data/lib/ecoportal/api/common/content/double_model/base.rb +29 -0
  42. data/lib/ecoportal/api/common/content/double_model/diffable_model.rb +43 -0
  43. data/lib/ecoportal/api/common/content/double_model/double_doc/base.rb +23 -0
  44. data/lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb +87 -0
  45. data/lib/ecoportal/api/common/content/double_model/double_doc/replaceable_doc.rb +61 -0
  46. data/lib/ecoportal/api/common/content/double_model/double_doc/reset_consolidate.rb +54 -0
  47. data/lib/ecoportal/api/common/content/double_model/double_doc/rooted_key.rb +49 -0
  48. data/lib/ecoportal/api/common/content/double_model/double_doc.rb +31 -0
  49. data/lib/ecoportal/api/common/content/double_model/hash_helpers.rb +40 -0
  50. data/lib/ecoportal/api/common/content/double_model/modifiers/read_only_able.rb +73 -0
  51. data/lib/ecoportal/api/common/content/double_model/modifiers/rootable.rb +64 -0
  52. data/lib/ecoportal/api/common/content/double_model/modifiers.rb +24 -0
  53. data/lib/ecoportal/api/common/content/double_model/parented.rb +22 -0
  54. data/lib/ecoportal/api/common/content/double_model/var_tracking.rb +45 -0
  55. data/lib/ecoportal/api/common/content/double_model.rb +28 -486
  56. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +2 -1
  57. data/lib/ecoportal/api/common/content/includer.rb +16 -0
  58. data/lib/ecoportal/api/common/content/model_helpers.rb +14 -16
  59. data/lib/ecoportal/api/common/content.rb +1 -0
  60. data/lib/ecoportal/api/v2/page/component.rb +46 -46
  61. data/lib/ecoportal/api/v2/page/components.rb +2 -2
  62. data/lib/ecoportal/api/v2/page.rb +14 -14
  63. data/lib/ecoportal/api/v2/pages/page_stage/task.rb +2 -2
  64. data/lib/ecoportal/api/v2/pages/page_stage/tasks.rb +3 -3
  65. data/lib/ecoportal/api/v2/pages/page_stage.rb +8 -8
  66. data/lib/ecoportal/api/v2/pages/stages.rb +2 -2
  67. data/lib/ecoportal/api/v2/pages.rb +15 -15
  68. data/lib/ecoportal/api/v2/registers.rb +20 -19
  69. data/lib/ecoportal/api/v2/s3/files/batch_upload.rb +1 -0
  70. data/lib/ecoportal/api/v2/s3/files/poll.rb +5 -5
  71. data/lib/ecoportal/api/v2/s3/files/poll_status.rb +3 -3
  72. data/lib/ecoportal/api/v2/s3/files.rb +6 -6
  73. data/lib/ecoportal/api/v2/s3.rb +5 -5
  74. data/lib/ecoportal/api/v2.rb +18 -8
  75. data/lib/ecoportal/api/v2_version.rb +1 -1
  76. metadata +50 -4
@@ -0,0 +1,40 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Model
7
+ module NumericKey
8
+ class << self
9
+ include Content::Includer
10
+
11
+ def included(base)
12
+ super
13
+
14
+ # to be able to call super:
15
+ include_missing(base, CollectionModel::Modifiers::ItemsKey)
16
+ include_missing(base, Model::Iterable)
17
+ base.send(:include, InstanceMethods)
18
+ end
19
+ end
20
+
21
+ # INSTANCE METHODS
22
+ module InstanceMethods
23
+ # Gets the `key` value of the object `value`.
24
+ # @note its name could be `fetch_key`.
25
+ # @return [String] the **value** of the `key`
26
+ # on the object `value`.
27
+ def get_key(value)
28
+ return super unless value.is_a?(Numeric)
29
+
30
+ # get_key(_items[value])
31
+ get_key(to_a[value])
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,50 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Model
7
+ module VarTracking
8
+ class << self
9
+ include Content::Includer
10
+
11
+ def included(base)
12
+ super
13
+
14
+ # to support call to super:
15
+ include_missing(base, DoubleModel::VarTracking)
16
+ include_missing(base, Model::Items)
17
+ include_missing(base, Model::NumericKey)
18
+ include_missing(base, Model::Cache)
19
+ base.send(:include, InstanceMethods)
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+ # protected
25
+
26
+ private # moved to private
27
+
28
+ # Helper to remove tracked down instance variables
29
+ def variable_remove!(key)
30
+ if @items_by_key && (k = get_key(key)) && (item = @items_by_key[k])
31
+ _items.delete(item) if _items.include?(item)
32
+ @items_by_key.delete(k)
33
+ else
34
+ super
35
+ end
36
+ end
37
+
38
+ # Removes all the persistent variables
39
+ def variables_remove!
40
+ @indexed = false
41
+ super
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+ require 'ecoportal/api/common/content/collection_model/model/items'
2
+ require 'ecoportal/api/common/content/collection_model/model/iterable'
3
+ require 'ecoportal/api/common/content/collection_model/model/numeric_key'
4
+ require 'ecoportal/api/common/content/collection_model/model/cache'
5
+ require 'ecoportal/api/common/content/collection_model/model/var_tracking'
6
+ require 'ecoportal/api/common/content/collection_model/model/lookup'
7
+
8
+ module Ecoportal
9
+ module API
10
+ module Common
11
+ module Content
12
+ class CollectionModel
13
+ module Model
14
+ class << self
15
+ include Content::Includer
16
+
17
+ def included(base)
18
+ super
19
+
20
+ include_missing(base, Items)
21
+ include_missing(base, Iterable)
22
+ include_missing(base, NumericKey)
23
+ include_missing(base, Cache)
24
+ include_missing(base, VarTracking)
25
+ include_missing(base, Lookup)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,57 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Modifiers
7
+ module ItemsKey
8
+ class << self
9
+ def included(base)
10
+ super
11
+ base.extend Content::ClassHelpers
12
+ base.extend ClassMethods
13
+ base.inheritable_class_vars :items_key
14
+ end
15
+ end
16
+
17
+ module ClassMethods
18
+ # The attr that has been defined as `passkey`
19
+ # in the item class
20
+ def items_key
21
+ @items_key ||= 'id'
22
+ end
23
+
24
+ def items_key=(value)
25
+ @items_key = value && value.to_s.freeze
26
+ end
27
+ end
28
+
29
+ # INSTANCE METHODS
30
+
31
+ protected
32
+
33
+ def items_key
34
+ self.class.items_key
35
+ end
36
+
37
+ # Gets the `key` value of the object `value`.
38
+ # @note its name could be `fetch_key`.
39
+ # @return [String] the **value** of the `key`
40
+ # on the object `value`.
41
+ def get_key(value)
42
+ case value
43
+ when Content::DoubleModel
44
+ value.key
45
+ when Hash
46
+ value[items_key]
47
+ when String
48
+ value
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,144 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Modifiers
7
+ module ItemsKlass
8
+ class << self
9
+ include Content::Includer
10
+
11
+ def included(base)
12
+ super
13
+ base.extend Content::ClassHelpers
14
+
15
+ include_missing(base, Modifiers::ItemsKey)
16
+
17
+ base.extend ClassMethods
18
+ base.inheritable_class_vars :klass, :new_item
19
+ end
20
+ end
21
+
22
+ module ClassMethods
23
+ NOT_USED = Content::ClassHelpers::NOT_USED
24
+
25
+ attr_writer :klass
26
+
27
+ # Optimization
28
+ def new_item_class_based?
29
+ return false if @new_item.is_a?(Proc)
30
+ return false if klass.is_a?(Proc)
31
+ return true if klass.is_a?(Class)
32
+
33
+ false
34
+ end
35
+
36
+ # @return [Boolean] are there the factory logics to build item objects defined?
37
+ def klass?
38
+ @klass || @new_item
39
+ end
40
+
41
+ # Resolves to the nuclear `Class` of the elements
42
+ # @note
43
+ # - use block to define `klass` callback
44
+ # @note When `klass` is resolved, if the items are of type
45
+ # `DoubleModel`, it sets on the collection class the `items_key`
46
+ # @note when `klass` is directly resolved (not via doc) only once
47
+ # it will set @klass as resolved and will use this class from now on.
48
+ # This is an optimization to cut class lookups
49
+ # @param value [Hash] base `doc` (raw object) to create the object with
50
+ # @yield [doc] identifies the target `class` of the raw object
51
+ # @yieldparam doc [Hash]
52
+ # @yieldreturn [Klass] the target `class`
53
+ # @return [Class, Proc, Hash] the target `class`
54
+ # - `Hash` tracks a symbol pending to be resovle from its referrer
55
+ # - `Class` an already resolve class
56
+ # - `Proc` a forker that pivots between multiple classes
57
+ def klass(value = NOT_USED, &block)
58
+ @klass = block if block_given?
59
+
60
+ if @klass.is_a?(Proc) && used_param?(value)
61
+ @klass.call(value)
62
+ elsif @klass && !@klass.is_a?(Proc) && !@klass.is_a?(Class)
63
+ @klass = resolve_class(@klass, exception: false)
64
+ @klass
65
+ else
66
+ @klass
67
+ end.tap do |result|
68
+ next unless result.is_a?(Class)
69
+ next unless result < Ecoportal::API::Common::Content::DoubleModel
70
+
71
+ self.items_key = result.key
72
+ end
73
+ end
74
+
75
+ # Generates a new object of the target class
76
+ # @note
77
+ # - use block to define `new_item` callback, which will prevail over `klass`
78
+ # - if `new_item` callback was **not** defined, it is required to defnie `klass`
79
+ # @param doc [Hash] doc to parse
80
+ # @note if block is given, it ignores `doc`
81
+ # @yield [doc, parent, key] creates an object instance of the target `klass`
82
+ # @yieldparam doc [Hash]
83
+ # @yieldreturn [Klass] instance object of the target `klass`
84
+ # @param parent [CollectionModel] the parent of the new item
85
+ # @param key [Symbol, String] the key value to access the item within collection
86
+ # Please observe that items in a CollectionModel are identified via their key attr.
87
+ # Meaning that there is actually no need to define this argument.
88
+ # @param read_only [Boolean] whether or not this new element should be
89
+ # created as read-only.
90
+ # @return [Klass] instance object of the target `klass`
91
+ def new_item(doc = NOT_USED, parent: nil, key: nil, read_only: false, &block)
92
+ if block_given?
93
+ @new_item = block
94
+ return
95
+ end
96
+
97
+ msg = 'To define the new_item callback (factory), you need to use a block'
98
+ raise msg unless used_param?(doc)
99
+
100
+ msg = 'You should define either a klass or a new_item callback first'
101
+ raise msg unless klass?
102
+
103
+ return @new_item.call(doc, parent, key) if @new_item.is_a?(Proc)
104
+
105
+ target_class = klass(doc)
106
+ raise "Could not find a class for: #{doc}" unless target_class
107
+
108
+ return doc if doc.is_a?(target_class)
109
+
110
+ target_class.new(doc, parent: parent, key: key, read_only: read_only)
111
+ end
112
+ end
113
+
114
+ # INSTANCE METHODS
115
+
116
+ # @return [Class] the class of the elements of the Collection
117
+ def items_class
118
+ self.class.klass
119
+ end
120
+
121
+ private
122
+
123
+ def new_item(value)
124
+ if self.class.new_item_class_based?
125
+ self.class.klass.new(
126
+ value,
127
+ parent: self,
128
+ read_only: read_only?
129
+ )
130
+ else
131
+ self.class.new_item(
132
+ value,
133
+ parent: self,
134
+ read_only: read_only?
135
+ )
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,38 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Modifiers
7
+ module ItemsOrder
8
+ class << self
9
+ def included(base)
10
+ super
11
+ base.extend Content::ClassHelpers
12
+ base.extend ClassMethods
13
+ base.inheritable_class_vars :order_matters, :order_key
14
+ end
15
+ end
16
+
17
+ module ClassMethods
18
+ attr_accessor :order_matters, :order_key
19
+ end
20
+
21
+ # INSTANCE METHODS
22
+
23
+ protected
24
+
25
+ def order_matters?
26
+ self.class.order_matters
27
+ end
28
+
29
+ def uniq?
30
+ self.class.uniq
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'ecoportal/api/common/content/collection_model/modifiers/items_key'
2
+ require 'ecoportal/api/common/content/collection_model/modifiers/items_klass'
3
+ require 'ecoportal/api/common/content/collection_model/modifiers/items_order'
4
+
5
+ module Ecoportal
6
+ module API
7
+ module Common
8
+ module Content
9
+ class CollectionModel
10
+ module Modifiers
11
+ class << self
12
+ include Content::Includer
13
+
14
+ def included(base)
15
+ super
16
+
17
+ include_missing(base, ItemsKey)
18
+ include_missing(base, ItemsKlass)
19
+ include_missing(base, ItemsOrder)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Mutation
7
+ module Clear
8
+ class << self
9
+ include Content::Includer
10
+
11
+ def included(base)
12
+ super
13
+ include_missing(base, CollectionModel::Model::Iterable)
14
+ include_missing(base, Mutation::Delete)
15
+ end
16
+ end
17
+
18
+ # INSTANCE METHODS
19
+
20
+ # Deletes all the elements of this `CollectionModel` instance
21
+ def clear
22
+ to_a.each {|item| delete!(item)}
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Mutation
7
+ module Delete
8
+ class << self
9
+ def included(base)
10
+ super
11
+ base.send(:include, CollectionModel::Doc::Items)
12
+ base.send(:include, CollectionModel::Model::Lookup)
13
+ base.send(:include, CollectionModel::DocMutation::Delete)
14
+ end
15
+ end
16
+
17
+ # INSTANCE METHODS
18
+
19
+ # Deletes `value` from this `CollectionModel` instance.
20
+ # @param value [String, Hash, Ecoportal::API::Common::Content::DoubleModel]
21
+ # - When used as `String`, the `key` value (i.e. `id` value) is expected.
22
+ # - When used as `Hash`, it should be the `doc` of the target element.
23
+ # - When used as `DoubleModel`, it should be the specific object to be deleted.
24
+ def delete!(value)
25
+ unless value.is_a?(Hash) || value.is_a?(Content::DoubleModel) || value.is_a?(String)
26
+ msg = 'Content::DoubleModel or Hash doc required'
27
+ raise ArgumentError, msg
28
+ end
29
+
30
+ return unless (item = self[value])
31
+
32
+ _doc_delete(item.doc)
33
+ @indexed = false
34
+ _items.delete(item)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,56 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ class CollectionModel
6
+ module Mutation
7
+ module Upsert
8
+ class << self
9
+ include Content::Includer
10
+
11
+ def included(base)
12
+ super
13
+ base.extend Content::ClassHelpers
14
+
15
+ include_missing(base, CollectionModel::Modifiers::ItemsKlass)
16
+ include_missing(base, CollectionModel::Model::Items)
17
+ include_missing(base, CollectionModel::Model::Lookup)
18
+ include_missing(base, CollectionModel::DocMutation::Upsert)
19
+ end
20
+ end
21
+
22
+ # INSTANCE METHODS
23
+
24
+ # Tries to find the element `value`, if it exists, it updates it
25
+ # Otherwise it pushes it to the end
26
+ # @value [Hash, Ecoportal::API::Common::Content::DoubleModel] the eleement to be added
27
+ # @return [Object] the `items_class` element object
28
+ def upsert!(value, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
29
+ unless value.is_a?(Hash) || value.is_a?(Content::DoubleModel)
30
+ msg = "'Content::DoubleModel' or 'Hash' doc required. Given #{value.class}"
31
+ raise ArgumentError, msg
32
+ end
33
+
34
+ item_doc = value.is_a?(Content::DoubleModel)? value.doc : value
35
+ item_doc = JSON.parse(item_doc.to_json)
36
+
37
+ if (item = self[value])
38
+ item.replace_doc(item_doc)
39
+ else
40
+ _doc_upsert(item_doc, pos: pos, before: before, after: after).tap do |pos_idx|
41
+ _items.insert(pos_idx, new_item(item_doc))
42
+ @indexed = false
43
+ end
44
+ end
45
+
46
+ (item || self[item_doc]).tap do |itm|
47
+ yield(itm) if block_given?
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ require 'ecoportal/api/common/content/collection_model/mutation/delete'
2
+ require 'ecoportal/api/common/content/collection_model/mutation/upsert'
3
+ require 'ecoportal/api/common/content/collection_model/mutation/clear'
4
+
5
+ module Ecoportal
6
+ module API
7
+ module Common
8
+ module Content
9
+ class CollectionModel
10
+ module Mutation
11
+ class << self
12
+ include Content::Includer
13
+
14
+ def included(base)
15
+ super
16
+
17
+ include_missing(base, Upsert)
18
+ include_missing(base, Delete)
19
+ include_missing(base, Clear)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end