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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +29 -3
- data/ecoportal-api-v2.gemspec +1 -1
- data/lib/ecoportal/api/common/content/array_model.rb +20 -3
- data/lib/ecoportal/api/common/content/class_helpers.rb +4 -2
- data/lib/ecoportal/api/common/content/client.rb +12 -6
- data/lib/ecoportal/api/common/content/collection_model/doc/items.rb +33 -0
- data/lib/ecoportal/api/common/content/collection_model/doc/rooted_key.rb +68 -0
- data/lib/ecoportal/api/common/content/collection_model/doc.rb +25 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation/delete.rb +33 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation/position.rb +42 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation/upsert.rb +45 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation.rb +27 -0
- data/lib/ecoportal/api/common/content/collection_model/model/cache.rb +44 -0
- data/lib/ecoportal/api/common/content/collection_model/model/items.rb +43 -0
- data/lib/ecoportal/api/common/content/collection_model/model/iterable.rb +44 -0
- data/lib/ecoportal/api/common/content/collection_model/model/lookup.rb +45 -0
- data/lib/ecoportal/api/common/content/collection_model/model/numeric_key.rb +40 -0
- data/lib/ecoportal/api/common/content/collection_model/model/var_tracking.rb +50 -0
- data/lib/ecoportal/api/common/content/collection_model/model.rb +33 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers/items_key.rb +57 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers/items_klass.rb +144 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers/items_order.rb +38 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers.rb +27 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation/clear.rb +30 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation/delete.rb +42 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation/upsert.rb +56 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation.rb +27 -0
- data/lib/ecoportal/api/common/content/collection_model.rb +19 -351
- data/lib/ecoportal/api/common/content/doc_helpers.rb +18 -16
- data/lib/ecoportal/api/common/content/double_model/attributable/base.rb +23 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/enforce.rb +62 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/cascaded_callback.rb +104 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/embeddable.rb +76 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/keyable.rb +119 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting.rb +136 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/passthrough.rb +70 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/simple.rb +48 -0
- data/lib/ecoportal/api/common/content/double_model/attributable.rb +30 -0
- data/lib/ecoportal/api/common/content/double_model/base.rb +29 -0
- data/lib/ecoportal/api/common/content/double_model/diffable_model.rb +43 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/base.rb +23 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb +87 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/replaceable_doc.rb +61 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/reset_consolidate.rb +54 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/rooted_key.rb +49 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc.rb +31 -0
- data/lib/ecoportal/api/common/content/double_model/hash_helpers.rb +40 -0
- data/lib/ecoportal/api/common/content/double_model/modifiers/read_only_able.rb +73 -0
- data/lib/ecoportal/api/common/content/double_model/modifiers/rootable.rb +64 -0
- data/lib/ecoportal/api/common/content/double_model/modifiers.rb +24 -0
- data/lib/ecoportal/api/common/content/double_model/parented.rb +22 -0
- data/lib/ecoportal/api/common/content/double_model/var_tracking.rb +45 -0
- data/lib/ecoportal/api/common/content/double_model.rb +28 -486
- data/lib/ecoportal/api/common/content/hash_diff_patch.rb +2 -1
- data/lib/ecoportal/api/common/content/includer.rb +16 -0
- data/lib/ecoportal/api/common/content/model_helpers.rb +14 -16
- data/lib/ecoportal/api/common/content.rb +1 -0
- data/lib/ecoportal/api/v2/page/component.rb +46 -46
- data/lib/ecoportal/api/v2/page/components.rb +2 -2
- data/lib/ecoportal/api/v2/page.rb +14 -14
- data/lib/ecoportal/api/v2/pages/page_stage/task.rb +2 -2
- data/lib/ecoportal/api/v2/pages/page_stage/tasks.rb +3 -3
- data/lib/ecoportal/api/v2/pages/page_stage.rb +8 -8
- data/lib/ecoportal/api/v2/pages/stages.rb +2 -2
- data/lib/ecoportal/api/v2/pages.rb +15 -15
- data/lib/ecoportal/api/v2/registers.rb +20 -19
- data/lib/ecoportal/api/v2/s3/files/batch_upload.rb +1 -0
- data/lib/ecoportal/api/v2/s3/files/poll.rb +5 -5
- data/lib/ecoportal/api/v2/s3/files/poll_status.rb +3 -3
- data/lib/ecoportal/api/v2/s3/files.rb +6 -6
- data/lib/ecoportal/api/v2/s3.rb +5 -5
- data/lib/ecoportal/api/v2.rb +18 -8
- data/lib/ecoportal/api/v2_version.rb +1 -1
- metadata +50 -4
@@ -0,0 +1,61 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module DoubleDoc
|
7
|
+
module ReplaceableDoc
|
8
|
+
include DoubleModel::VarTracking
|
9
|
+
|
10
|
+
class << self
|
11
|
+
include Content::Includer
|
12
|
+
|
13
|
+
def included(base)
|
14
|
+
super
|
15
|
+
|
16
|
+
include_missing(base, DoubleModel::HashHelpers)
|
17
|
+
include_missing(base, DoubleDoc::Base)
|
18
|
+
include_missing(base, DoubleDoc::RootedKey)
|
19
|
+
include_missing(base, DoubleDoc::LinkableDoc)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# INSTANCE METHODS
|
24
|
+
|
25
|
+
def replace_doc(new_doc)
|
26
|
+
return (@doc = new_doc) if root?
|
27
|
+
|
28
|
+
unless linked?
|
29
|
+
raise UnlinkedModel.new(
|
30
|
+
from: "#{self.class}##{__method__}",
|
31
|
+
key: _parent_key
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
dig_set(_parent.doc, resolved_rooted_doc_key, new_doc)
|
36
|
+
|
37
|
+
_parent.variable_remove!(_parent_key) unless new_doc
|
38
|
+
#variables_remove!
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def replace_original_doc(new_doc)
|
44
|
+
return (@original_doc = new_doc) if root?
|
45
|
+
|
46
|
+
unless linked?
|
47
|
+
raise UnlinkedModel.new(
|
48
|
+
from: "#{self.class}##{__method__}",
|
49
|
+
key: _parent_key
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
dig_set(_parent.original_doc, resolved_rooted_doc_key, new_doc)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module DoubleDoc
|
7
|
+
module ResetConsolidate
|
8
|
+
include DoubleModel::VarTracking
|
9
|
+
|
10
|
+
class << self
|
11
|
+
include Content::Includer
|
12
|
+
|
13
|
+
def included(base)
|
14
|
+
super
|
15
|
+
|
16
|
+
include_missing(base, DoubleDoc::Base)
|
17
|
+
include_missing(base, DoubleDoc::RootedKey)
|
18
|
+
include_missing(base, DoubleDoc::LinkableDoc)
|
19
|
+
include_missing(base, DoubleDoc::ReplaceableDoc)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# INSTANCE METHODS
|
24
|
+
|
25
|
+
# It makes `original_doc` to be like `doc`
|
26
|
+
# @note
|
27
|
+
# - after executing it, there will be no pending changes
|
28
|
+
# - you should technically run this command, after a successful update request to the server
|
29
|
+
def consolidate!
|
30
|
+
replace_original_doc(JSON.parse(doc.to_json))
|
31
|
+
end
|
32
|
+
|
33
|
+
# It makes `doc` to be like `original`
|
34
|
+
# @note
|
35
|
+
# - after executing it, changes in `doc` will be lost
|
36
|
+
# - you should technically run this command only if you want to remove certain changes
|
37
|
+
# @key [Symbol] the specific part of the model you want to `reset`
|
38
|
+
def reset!(key = nil)
|
39
|
+
if key
|
40
|
+
keys = [key].flatten.compact
|
41
|
+
odoc = original_doc.dig(*keys)
|
42
|
+
odoc &&= JSON.parse(odoc.to_json)
|
43
|
+
dig_set(doc, keys, odoc)
|
44
|
+
else
|
45
|
+
replace_doc(JSON.parse(original_doc.to_json))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module DoubleDoc
|
7
|
+
module RootedKey
|
8
|
+
class << self
|
9
|
+
include Content::Includer
|
10
|
+
|
11
|
+
def included(base)
|
12
|
+
super
|
13
|
+
|
14
|
+
include_missing(base, DoubleDoc::Base)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# INSTANCE METHODS
|
19
|
+
|
20
|
+
# Offers a method for child classes to transform the key,
|
21
|
+
# provided that the child's `doc` can be accessed.
|
22
|
+
# @note this method can't be protected. It might be accessed by cousing classes.
|
23
|
+
# See last line of this method.
|
24
|
+
# parent class to a child class.
|
25
|
+
def _rooted_doc_key(value)
|
26
|
+
#print "!(#{value}<=#{self.class})" if value.is_a?(Content::DoubleModel) && !value.root?
|
27
|
+
return value unless value.is_a?(Content::DoubleModel)
|
28
|
+
return value if value.root?
|
29
|
+
|
30
|
+
#print "?(#{value.class}<=#{value._parent.class})"
|
31
|
+
value._parent._rooted_doc_key(value)
|
32
|
+
end
|
33
|
+
# alias_method :_doc_key, :_rooted_doc_key
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
# @note this method can be protected... not accessed from
|
38
|
+
# parent class to child class.
|
39
|
+
def resolved_rooted_doc_key
|
40
|
+
[_rooted_doc_key(_parent_key)].flatten
|
41
|
+
end
|
42
|
+
# alias_method :resolved_doc_key, :resolved_rooted_doc_key
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ecoportal/api/common/content/double_model/double_doc/base'
|
2
|
+
require 'ecoportal/api/common/content/double_model/double_doc/rooted_key'
|
3
|
+
require 'ecoportal/api/common/content/double_model/double_doc/linkable_doc'
|
4
|
+
require 'ecoportal/api/common/content/double_model/double_doc/replaceable_doc'
|
5
|
+
require 'ecoportal/api/common/content/double_model/double_doc/reset_consolidate'
|
6
|
+
|
7
|
+
module Ecoportal
|
8
|
+
module API
|
9
|
+
module Common
|
10
|
+
module Content
|
11
|
+
class DoubleModel
|
12
|
+
module DoubleDoc
|
13
|
+
class << self
|
14
|
+
include Content::Includer
|
15
|
+
|
16
|
+
def included(base)
|
17
|
+
super
|
18
|
+
|
19
|
+
include_missing(base, Base)
|
20
|
+
include_missing(base, RootedKey)
|
21
|
+
include_missing(base, LinkableDoc)
|
22
|
+
include_missing(base, ReplaceableDoc)
|
23
|
+
include_missing(base, ResetConsolidate)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module HashHelpers
|
7
|
+
private
|
8
|
+
|
9
|
+
# It sets `value` on the last object that you would get
|
10
|
+
# via `obj.dig(*keys[0..-1])`
|
11
|
+
# @note equivalent to `obj.dig(*keys[0..-1])&[keys.last] = value`
|
12
|
+
def dig_set(obj, keys, value)
|
13
|
+
if keys.length == 1
|
14
|
+
obj[keys.first] = value
|
15
|
+
else
|
16
|
+
dig_set(obj[keys.first], keys.slice(1..-1), value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# It sets `value` on the last object that you would get
|
21
|
+
# via `obj.dig(*keys[0..-1])`
|
22
|
+
# @note equivalent to
|
23
|
+
# 1. `parent = obj.dig(*keys[0..-1])`
|
24
|
+
# 2. `parent.delete(keys.last) if parent.is_a?(Hash)`
|
25
|
+
# @return [Variant] the value of that key
|
26
|
+
def dig_delete(obj, keys)
|
27
|
+
if keys.length == 1
|
28
|
+
return unless obj.respond_to?(:delete)
|
29
|
+
|
30
|
+
obj.delete(keys.first)
|
31
|
+
else
|
32
|
+
dig_delete(obj[keys.first], keys.slice(1..-1))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module Modifiers
|
7
|
+
module ReadOnlyAble
|
8
|
+
class << self
|
9
|
+
include Content::Includer
|
10
|
+
|
11
|
+
def included(base)
|
12
|
+
super
|
13
|
+
base.extend Content::ClassHelpers
|
14
|
+
|
15
|
+
include_missing(base, DoubleModel::Parented)
|
16
|
+
include_missing(base, Modifiers::Rootable)
|
17
|
+
|
18
|
+
base.extend ClassMethods
|
19
|
+
base.inheritable_class_vars :read_only
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
# @note when defined as root of the model, it isn't read-only
|
25
|
+
def read_only?
|
26
|
+
@read_only = false if @read_only.nil?
|
27
|
+
return false if root?
|
28
|
+
|
29
|
+
@read_only
|
30
|
+
end
|
31
|
+
|
32
|
+
# Be able to define if a class should be read-only
|
33
|
+
# @note this propagates to all the nested models thereof.
|
34
|
+
def read_only!
|
35
|
+
@read_only = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# INSTANCE METHODS
|
40
|
+
|
41
|
+
# @note `read_only` allows for some optimizations, such as storing values
|
42
|
+
# in instance variables, for optimization purposes
|
43
|
+
def read_only?
|
44
|
+
_read_only || false
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def _read_only
|
50
|
+
@_read_only = self.class.read_only? if @_read_only.nil?
|
51
|
+
@_read_only
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Boolean] whether this should be the root of the model
|
55
|
+
def to_be_root?
|
56
|
+
return true if _parent == self
|
57
|
+
return true if read_only?
|
58
|
+
|
59
|
+
self.class.root?
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def read_only!
|
65
|
+
@_read_only = true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module Modifiers
|
7
|
+
module Rootable
|
8
|
+
class << self
|
9
|
+
include Content::Includer
|
10
|
+
|
11
|
+
def included(base)
|
12
|
+
super
|
13
|
+
|
14
|
+
include_missing(base, DoubleModel::Parented)
|
15
|
+
|
16
|
+
base.extend ClassMethods
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
# @return [Boolean] whether this is the top of the doc model
|
22
|
+
# and should not make its nested models read-only (rooted on their own)
|
23
|
+
def root?
|
24
|
+
@start_root
|
25
|
+
end
|
26
|
+
|
27
|
+
# @note that this method stops the propagation of read_only!
|
28
|
+
# @note that this method only affects the current model.
|
29
|
+
def root!
|
30
|
+
@start_root = false if @start_root.nil?
|
31
|
+
@start_root = true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# INSTANCE METHODS
|
36
|
+
|
37
|
+
def root
|
38
|
+
return self if root?
|
39
|
+
|
40
|
+
_parent.root
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def doc_var?
|
46
|
+
!!defined?(@doc)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Both requisites
|
50
|
+
# @note that for optimization purposes, `@doc` var may be used when
|
51
|
+
# the object is `read_only?`
|
52
|
+
# @note we check on @doc instance variable defined, to ensure what
|
53
|
+
# we have already rooted this object's subjacent model (doc)
|
54
|
+
# within itself.
|
55
|
+
def root?
|
56
|
+
_parent == self && doc_var?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ecoportal/api/common/content/double_model/modifiers/rootable'
|
2
|
+
require 'ecoportal/api/common/content/double_model/modifiers/read_only_able'
|
3
|
+
|
4
|
+
module Ecoportal
|
5
|
+
module API
|
6
|
+
module Common
|
7
|
+
module Content
|
8
|
+
class DoubleModel
|
9
|
+
module Modifiers
|
10
|
+
class << self
|
11
|
+
include Content::Includer
|
12
|
+
|
13
|
+
def included(base)
|
14
|
+
super
|
15
|
+
include_missing(base, ReadOnlyAble)
|
16
|
+
include_missing(base, Rootable)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module Parented
|
7
|
+
attr_reader :_parent, :_parent_key
|
8
|
+
|
9
|
+
# `_key` refers to the `_parent`'s property that links to this model.
|
10
|
+
# @note on the other hand, `key` rather refers to the **value**
|
11
|
+
# of the key property (identifies an item in a set of elements)
|
12
|
+
alias_method :_key, :_parent_key
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
attr_writer :_parent, :_parent_key
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Content
|
5
|
+
class DoubleModel
|
6
|
+
module VarTracking
|
7
|
+
protected
|
8
|
+
|
9
|
+
# Helper to track down persistent variables
|
10
|
+
def variable_set(key, value)
|
11
|
+
var = instance_variable_name(key)
|
12
|
+
_dim_vars.push(var).uniq!
|
13
|
+
instance_variable_set(var, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Helper to remove tracked down instance variables
|
17
|
+
def variable_remove!(key)
|
18
|
+
var = instance_variable_name(key)
|
19
|
+
return unless _dim_vars.include?(var)
|
20
|
+
|
21
|
+
_dim_vars.delete(var)
|
22
|
+
remove_instance_variable(var)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Removes all the persistent variables
|
26
|
+
def variables_remove!
|
27
|
+
#puts "going to remove vars: #{_dim_vars} on #{self.class} (parent: #{identify_parent(self._parent)})"
|
28
|
+
_dim_vars.dup.map {|var| variable_remove!(var)}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def _dim_vars
|
34
|
+
@_dim_vars ||= []
|
35
|
+
end
|
36
|
+
|
37
|
+
def instance_variable_name(key)
|
38
|
+
self.class.instance_variable_name(key)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|