ledger_sync 2.6.0 → 3.0.2
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/.github/dependabot.yml +9 -0
- data/.github/workflows/gem-workflow.yml +11 -9
- data/.gitignore +3 -1
- data/.rubocop.yml +7 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +140 -114
- data/documentation/generators/generator.rb +1 -1
- data/documentation/generators/reference/generator.rb +1 -3
- data/documentation/generators/template.rb +1 -1
- data/ledger_sync.gemspec +22 -23
- data/lib/ledger_sync/deserializer.rb +4 -4
- data/lib/ledger_sync/error/ledger_errors.rb +2 -8
- data/lib/ledger_sync/error/operation_errors.rb +1 -0
- data/lib/ledger_sync/error/resource_errors.rb +2 -2
- data/lib/ledger_sync/ledger_configuration_store.rb +4 -4
- data/lib/ledger_sync/ledgers/client.rb +3 -3
- data/lib/ledger_sync/ledgers/mixins/infer_serializer_mixin.rb +12 -24
- data/lib/ledger_sync/ledgers/mixins/infer_validation_contract_mixin.rb +3 -5
- data/lib/ledger_sync/resource.rb +5 -5
- data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +2 -2
- data/lib/ledger_sync/serialization/mixin.rb +1 -1
- data/lib/ledger_sync/serializer.rb +4 -4
- data/lib/ledger_sync/test/support/factory_bot.rb +2 -2
- data/lib/ledger_sync/test/support/qa/ledger_support_setup.rb +2 -2
- data/lib/ledger_sync/test/support/record_collection.rb +1 -1
- data/lib/ledger_sync/type/reference_many.rb +1 -1
- data/lib/ledger_sync/type/value_mixin.rb +1 -1
- data/lib/ledger_sync/util/dotenv_updator.rb +1 -1
- data/lib/ledger_sync/util/resource_converter/attribute_set.rb +1 -1
- data/lib/ledger_sync/util/resource_converter.rb +8 -8
- data/lib/ledger_sync/util/resources_builder.rb +23 -25
- data/lib/ledger_sync/util/signer.rb +4 -2
- data/lib/ledger_sync/util/string_helpers.rb +1 -1
- data/lib/ledger_sync/version.rb +2 -2
- metadata +47 -45
@@ -30,9 +30,9 @@ module LedgerSync
|
|
30
30
|
def ledger_attributes_to_save
|
31
31
|
return {} if self.class.ledger_attributes_to_save.nil?
|
32
32
|
|
33
|
-
|
33
|
+
self.class.ledger_attributes_to_save.to_h do |attribute|
|
34
34
|
[attribute, send(attribute)]
|
35
|
-
end
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def operation_for(args = {})
|
@@ -98,7 +98,7 @@ module LedgerSync
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def resource_from_ledger_type(type:, converter: nil)
|
101
|
-
converter ||= proc
|
101
|
+
converter ||= proc(&:underscore)
|
102
102
|
ledger_resource_type_overrides.invert[converter.call(type).to_sym] || resources[converter.call(type).to_sym]
|
103
103
|
end
|
104
104
|
|
@@ -9,45 +9,33 @@ module LedgerSync
|
|
9
9
|
module InferSerializerMixin
|
10
10
|
module ClassMethods
|
11
11
|
def inferred_deserializer_class
|
12
|
-
@inferred_deserializer_class ||=
|
13
|
-
|
14
|
-
|
15
|
-
)
|
16
|
-
end
|
12
|
+
@inferred_deserializer_class ||= inferred_config.base_module.const_get(
|
13
|
+
inferred_deserializer_class_name
|
14
|
+
)
|
17
15
|
end
|
18
16
|
|
19
17
|
def inferred_deserializer_class_name
|
20
|
-
@inferred_deserializer_class_name ||=
|
21
|
-
"#{inferred_resource_class}::Deserializer"
|
22
|
-
end
|
18
|
+
@inferred_deserializer_class_name ||= "#{inferred_resource_class}::Deserializer"
|
23
19
|
end
|
24
20
|
|
25
21
|
def inferred_searcher_deserializer_class
|
26
|
-
@inferred_searcher_deserializer_class ||=
|
27
|
-
|
28
|
-
|
29
|
-
)
|
30
|
-
end
|
22
|
+
@inferred_searcher_deserializer_class ||= inferred_config.base_module.const_get(
|
23
|
+
inferred_searcher_deserializer_class_name
|
24
|
+
)
|
31
25
|
end
|
32
26
|
|
33
27
|
def inferred_searcher_deserializer_class_name
|
34
|
-
@inferred_searcher_deserializer_class_name ||=
|
35
|
-
"#{inferred_resource_class}::SearcherDeserializer"
|
36
|
-
end
|
28
|
+
@inferred_searcher_deserializer_class_name ||= "#{inferred_resource_class}::SearcherDeserializer"
|
37
29
|
end
|
38
30
|
|
39
31
|
def inferred_serializer_class
|
40
|
-
@inferred_serializer_class ||=
|
41
|
-
|
42
|
-
|
43
|
-
)
|
44
|
-
end
|
32
|
+
@inferred_serializer_class ||= inferred_config.base_module.const_get(
|
33
|
+
inferred_serializer_class_name
|
34
|
+
)
|
45
35
|
end
|
46
36
|
|
47
37
|
def inferred_serializer_class_name
|
48
|
-
@inferred_serializer_class_name ||=
|
49
|
-
"#{inferred_resource_class}::Serializer"
|
50
|
-
end
|
38
|
+
@inferred_serializer_class_name ||= "#{inferred_resource_class}::Serializer"
|
51
39
|
end
|
52
40
|
end
|
53
41
|
|
@@ -6,11 +6,9 @@ module LedgerSync
|
|
6
6
|
module InferValidationContractMixin
|
7
7
|
module ClassMethods
|
8
8
|
def inferred_validation_contract_class
|
9
|
-
@inferred_validation_contract_class ||=
|
10
|
-
|
11
|
-
|
12
|
-
)
|
13
|
-
end
|
9
|
+
@inferred_validation_contract_class ||= const_get(
|
10
|
+
inferred_validation_contract_class_name
|
11
|
+
)
|
14
12
|
end
|
15
13
|
|
16
14
|
def inferred_validation_contract_class_name
|
data/lib/ledger_sync/resource.rb
CHANGED
@@ -44,13 +44,13 @@ module LedgerSync
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def changed?
|
47
|
-
super || resource_attributes.references_many.
|
47
|
+
super || resource_attributes.references_many.any?(&:changed?)
|
48
48
|
end
|
49
49
|
|
50
50
|
def changes
|
51
|
-
super.merge(
|
52
|
-
|
53
|
-
|
51
|
+
super.merge(resource_attributes.references_many.map do |ref|
|
52
|
+
[ref.name, ref.changes['value']] if ref.changed?
|
53
|
+
end.compact.to_h)
|
54
54
|
end
|
55
55
|
|
56
56
|
def class_from_resource_type(obj)
|
@@ -62,7 +62,7 @@ module LedgerSync
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.inherited(subclass)
|
65
|
-
resource_attributes.
|
65
|
+
resource_attributes.each_value do |resource_attribute|
|
66
66
|
subclass._add_resource_attribute(resource_attribute)
|
67
67
|
end
|
68
68
|
|
@@ -40,12 +40,12 @@ module LedgerSync
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def dirty_attributes_to_h
|
43
|
-
|
43
|
+
self.class.dirty_attributes.keys.to_h do |k|
|
44
44
|
[
|
45
45
|
k,
|
46
46
|
public_send(k)
|
47
47
|
]
|
48
|
-
end
|
48
|
+
end
|
49
49
|
end
|
50
50
|
|
51
51
|
# Normally you would just call `changes_applied`, but because we
|
@@ -60,7 +60,7 @@ module LedgerSync
|
|
60
60
|
@attributes ||= Serialization::SerializerAttributeSet.new(serializer_class: self)
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.references_one(hash_attribute, args = {}, &
|
63
|
+
def self.references_one(hash_attribute, args = {}, &)
|
64
64
|
attribute(
|
65
65
|
hash_attribute,
|
66
66
|
{
|
@@ -68,11 +68,11 @@ module LedgerSync
|
|
68
68
|
serializer: serializer_from(hash_attribute, args)
|
69
69
|
)
|
70
70
|
}.merge(args),
|
71
|
-
&
|
71
|
+
&
|
72
72
|
)
|
73
73
|
end
|
74
74
|
|
75
|
-
def self.references_many(hash_attribute, args = {}, &
|
75
|
+
def self.references_many(hash_attribute, args = {}, &)
|
76
76
|
attribute(
|
77
77
|
hash_attribute,
|
78
78
|
{
|
@@ -80,7 +80,7 @@ module LedgerSync
|
|
80
80
|
serializer: serializer_from(hash_attribute, args)
|
81
81
|
)
|
82
82
|
}.merge(args),
|
83
|
-
&
|
83
|
+
&
|
84
84
|
)
|
85
85
|
end
|
86
86
|
|
@@ -65,7 +65,7 @@ end
|
|
65
65
|
def generate_resource_factories
|
66
66
|
LedgerSync.ledgers.each do |ledger_key, ledger|
|
67
67
|
ledger.client_class.resources.each do |resource_key, resource_class|
|
68
|
-
factory_key = "#{ledger_key}_#{resource_key}"
|
68
|
+
factory_key = :"#{ledger_key}_#{resource_key}"
|
69
69
|
next if FactoryBot.factories.registered?(factory_key)
|
70
70
|
|
71
71
|
register_factory(prefix: ledger_key, resource_class: resource_class)
|
@@ -101,7 +101,7 @@ module FactoryBot
|
|
101
101
|
def self.test_run_id(*appends, **keywords)
|
102
102
|
@test_run_id ||= rand_id(
|
103
103
|
*appends,
|
104
|
-
**keywords
|
104
|
+
**keywords, include_test_run_id: false
|
105
105
|
)
|
106
106
|
end
|
107
107
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
def setup_client_qa_support(*clients, keyed: false) # rubocop:disable Metrics/PerceivedComplexity
|
4
|
-
qa_clients =
|
4
|
+
qa_clients = clients.uniq.to_h do |client|
|
5
5
|
key = client.config.root_key
|
6
6
|
|
7
7
|
qa_support "#{key}_helpers"
|
@@ -14,7 +14,7 @@ def setup_client_qa_support(*clients, keyed: false) # rubocop:disable Metrics/Pe
|
|
14
14
|
key: key
|
15
15
|
}
|
16
16
|
]
|
17
|
-
end
|
17
|
+
end
|
18
18
|
|
19
19
|
RSpec.configure do |config|
|
20
20
|
qa_clients.each_value do |data|
|
@@ -29,7 +29,7 @@ module LedgerSync
|
|
29
29
|
Gem.find_files(File.join(dir, '*.json')).map do |file_path|
|
30
30
|
record = File.basename(file_path, '.json').to_sym
|
31
31
|
@records[record] = record_class.new(
|
32
|
-
hash: JSON.parse(File.
|
32
|
+
hash: JSON.parse(File.read(file_path)),
|
33
33
|
path: file_path,
|
34
34
|
record: record
|
35
35
|
)
|
@@ -35,7 +35,7 @@ module LedgerSync
|
|
35
35
|
def valid?(args = {})
|
36
36
|
value = args.fetch(:value)
|
37
37
|
return false unless value.is_a?(Array)
|
38
|
-
return true if (
|
38
|
+
return true if resource_classes.intersect?(value.map(&:class))
|
39
39
|
return true if value.is_a?(Array) && value.empty?
|
40
40
|
|
41
41
|
false
|
@@ -24,7 +24,7 @@ module LedgerSync
|
|
24
24
|
client_method = env_key.split(prefix).last.downcase
|
25
25
|
|
26
26
|
if line =~ /\A#{prefix}/ && to_save.key?(client_method)
|
27
|
-
env_value = ENV
|
27
|
+
env_value = ENV.fetch(env_key, nil)
|
28
28
|
new_value = to_save.delete(client_method)
|
29
29
|
tempfile.puts "#{env_key}=#{new_value}"
|
30
30
|
next if env_value == new_value.to_s
|
@@ -22,7 +22,7 @@ module LedgerSync
|
|
22
22
|
def add(attribute)
|
23
23
|
unless attribute.destination_attribute.nil?
|
24
24
|
if @attribute_keys.key?(attribute.destination_attribute.to_s)
|
25
|
-
raise "destination_attribute already defined for #{resource_converter_class.name}: "\
|
25
|
+
raise "destination_attribute already defined for #{resource_converter_class.name}: " \
|
26
26
|
"#{attribute.destination_attribute}"
|
27
27
|
end
|
28
28
|
|
@@ -54,15 +54,15 @@ module LedgerSync
|
|
54
54
|
)
|
55
55
|
end
|
56
56
|
|
57
|
-
def self.attribute(
|
58
|
-
_attribute(
|
57
|
+
def self.attribute(...)
|
58
|
+
_attribute(...)
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.attributes
|
62
62
|
@attributes ||= ResourceConverter::AttributeSet.new(resource_converter_class: self)
|
63
63
|
end
|
64
64
|
|
65
|
-
def self._references(destination_attribute = nil, args = {}, &
|
65
|
+
def self._references(destination_attribute = nil, args = {}, &)
|
66
66
|
reference_type = args.fetch(:reference_type)
|
67
67
|
resource_converter = args.fetch(:resource_converter)
|
68
68
|
|
@@ -89,27 +89,27 @@ module LedgerSync
|
|
89
89
|
]
|
90
90
|
)
|
91
91
|
),
|
92
|
-
&
|
92
|
+
&
|
93
93
|
)
|
94
94
|
end
|
95
95
|
|
96
|
-
def self.references_one(destination_attribute = nil, args = {}, &
|
96
|
+
def self.references_one(destination_attribute = nil, args = {}, &)
|
97
97
|
_references(
|
98
98
|
destination_attribute,
|
99
99
|
{
|
100
100
|
reference_type: :one
|
101
101
|
}.merge(args),
|
102
|
-
&
|
102
|
+
&
|
103
103
|
)
|
104
104
|
end
|
105
105
|
|
106
|
-
def self.references_many(destination_attribute = nil, args = {}, &
|
106
|
+
def self.references_many(destination_attribute = nil, args = {}, &)
|
107
107
|
_references(
|
108
108
|
destination_attribute,
|
109
109
|
{
|
110
110
|
reference_type: :many
|
111
111
|
}.merge(args),
|
112
|
-
&
|
112
|
+
&
|
113
113
|
)
|
114
114
|
end
|
115
115
|
end
|
@@ -51,37 +51,35 @@ module LedgerSync
|
|
51
51
|
end
|
52
52
|
raise "#{type} is an invalid resource type" if resource_class.nil?
|
53
53
|
|
54
|
-
current_data =
|
55
|
-
|
56
|
-
k = k.to_sym
|
54
|
+
current_data = current_data.to_h do |k, v|
|
55
|
+
k = k.to_sym
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
attribute = resource_class.resource_attributes[k]
|
58
|
+
if attribute.nil? && !ignore_unrecognized_attributes
|
59
|
+
raise "Unrecognized attribute for #{resource_class.name}: #{k}"
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
v = if attribute.is_a?(ResourceAttribute::Reference::One)
|
63
|
+
resource_type = resource_type_by(external_id: current_data[k])
|
64
|
+
resource_or_build(
|
65
|
+
external_id: current_data[k],
|
66
|
+
type: resource_type
|
67
|
+
)
|
68
|
+
elsif attribute.is_a?(ResourceAttribute::Reference::Many)
|
69
|
+
current_data[k].map do |many_reference|
|
65
70
|
resource_or_build(
|
66
|
-
external_id:
|
67
|
-
type: resource_type
|
71
|
+
external_id: many_reference,
|
72
|
+
type: attribute.type.resource_class.resource_type
|
68
73
|
)
|
69
|
-
elsif attribute.is_a?(ResourceAttribute::Reference::Many)
|
70
|
-
current_data[k].map do |many_reference|
|
71
|
-
resource_or_build(
|
72
|
-
external_id: many_reference,
|
73
|
-
type: attribute.type.resource_class.resource_type
|
74
|
-
)
|
75
|
-
end
|
76
|
-
elsif cast
|
77
|
-
attribute.type.cast(value: v)
|
78
|
-
else
|
79
|
-
v
|
80
74
|
end
|
75
|
+
elsif cast
|
76
|
+
attribute.type.cast(value: v)
|
77
|
+
else
|
78
|
+
v
|
79
|
+
end
|
81
80
|
|
82
|
-
|
83
|
-
|
84
|
-
]
|
81
|
+
[k, v]
|
82
|
+
end
|
85
83
|
|
86
84
|
@all_resources[resource_key(external_id: external_id, type: type)] ||= resource_class.new(
|
87
85
|
external_id: external_id,
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'base64'
|
4
|
+
|
3
5
|
module LedgerSync
|
4
6
|
module Util
|
5
7
|
class Signer
|
@@ -25,11 +27,11 @@ module LedgerSync
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.escape(str:)
|
28
|
-
CGI.escape(str).gsub(
|
30
|
+
CGI.escape(str).gsub('+', '%20')
|
29
31
|
end
|
30
32
|
|
31
33
|
def self.unescape(str:)
|
32
|
-
CGI.unescape(str.gsub(
|
34
|
+
CGI.unescape(str.gsub('%20', '+'))
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
data/lib/ledger_sync/version.rb
CHANGED