ledger_sync-domains 1.2.1 → 1.4.0
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/ruby.yml +63 -26
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/.tool-versions +1 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +61 -51
- data/README.md +1 -1
- data/ledger_sync-domains.gemspec +7 -6
- data/lib/ledger_sync/domains/operation/transition.rb +1 -2
- data/lib/ledger_sync/domains/operation.rb +97 -33
- data/lib/ledger_sync/domains/serializer/mixin.rb +74 -0
- data/lib/ledger_sync/domains/serializer/struct.rb +2 -0
- data/lib/ledger_sync/domains/serializer.rb +13 -22
- data/lib/ledger_sync/domains/version.rb +1 -1
- data/lib/ledger_sync/domains.rb +38 -0
- metadata +31 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71024173b5e0ae4d6ca40a4f62b6f234c6a15e7a0756cff7116fa3b322e91c52
|
4
|
+
data.tar.gz: '091337e4d803d44e6c43c64885a276b007ce26184ef6a1846592d7f498e153a9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58b8cbff85ea3f5c9146d3880259daf015a512dbb24cb8e76a1fc50cae7a134300e96d1a20e9b55ea181463049f045c23e5ce8964e0372eb7ce8abf328c30f9d
|
7
|
+
data.tar.gz: fe06abad6bc035f5fca8305a3d730ab859a01180ffe72b5070d1a683eedbff1d900bc1340a1855d261f6bf31f87c152efa8f385f29b0f22a24a74aeddb86c8dc
|
data/.github/workflows/ruby.yml
CHANGED
@@ -1,36 +1,73 @@
|
|
1
|
-
|
2
|
-
# They are provided by a third-party and are governed by
|
3
|
-
# separate terms of service, privacy policy, and support
|
4
|
-
# documentation.
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
-
|
8
|
-
name: Ruby
|
9
|
-
|
1
|
+
name: Test and Deploy
|
10
2
|
on:
|
11
3
|
push:
|
12
|
-
branches: [main]
|
13
4
|
pull_request:
|
14
|
-
|
15
|
-
|
5
|
+
release:
|
6
|
+
types: [created]
|
16
7
|
jobs:
|
17
|
-
|
18
|
-
|
8
|
+
rubocop:
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
ruby-version: ["3.1", "3.2", "3.3"]
|
12
|
+
runs-on: [ubuntu-latest]
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
with:
|
16
|
+
persist-credentials: false
|
17
|
+
fetch-depth: 0
|
18
|
+
- name: Ruby Setup and Bundle
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
22
|
+
bundler-cache: true
|
23
|
+
run: |
|
24
|
+
gem install bundler
|
25
|
+
bundle update
|
26
|
+
bundle install
|
27
|
+
- run: bundle exec rubocop
|
28
|
+
rspec:
|
19
29
|
strategy:
|
20
30
|
matrix:
|
21
|
-
ruby-version: ["
|
22
|
-
|
31
|
+
ruby-version: ["3.1", "3.2", "3.3"]
|
32
|
+
runs-on: [ubuntu-latest]
|
23
33
|
steps:
|
24
|
-
- uses: actions/checkout@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
uses: ruby/setup-ruby@
|
34
|
+
- uses: actions/checkout@v3
|
35
|
+
with:
|
36
|
+
persist-credentials: false
|
37
|
+
fetch-depth: 0
|
38
|
+
- name: Ruby Setup and Bundle
|
39
|
+
uses: ruby/setup-ruby@v1
|
30
40
|
with:
|
31
41
|
ruby-version: ${{ matrix.ruby-version }}
|
32
|
-
bundler-cache: true
|
33
|
-
|
42
|
+
bundler-cache: true
|
43
|
+
run: |
|
44
|
+
gem install bundler
|
45
|
+
bundle update
|
46
|
+
bundle install
|
47
|
+
- name: rspec
|
34
48
|
run: bundle exec rspec
|
35
|
-
|
36
|
-
|
49
|
+
publish:
|
50
|
+
runs-on: ubuntu-latest
|
51
|
+
needs: ["rubocop", "rspec"]
|
52
|
+
if: github.event_name == 'release' && github.event.action == 'created'
|
53
|
+
steps:
|
54
|
+
- name: Checkout
|
55
|
+
uses: actions/checkout@v3
|
56
|
+
with:
|
57
|
+
persist-credentials: false
|
58
|
+
fetch-depth: 0
|
59
|
+
- name: Ruby Setup and Bundle
|
60
|
+
uses: ruby/setup-ruby@v1
|
61
|
+
with:
|
62
|
+
ruby-version: 3.1
|
63
|
+
bundler-cache: true
|
64
|
+
- name: Publish to RubyGems
|
65
|
+
run: |
|
66
|
+
mkdir -p $HOME/.gem
|
67
|
+
touch $HOME/.gem/credentials
|
68
|
+
chmod 0600 $HOME/.gem/credentials
|
69
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
70
|
+
gem build *.gemspec
|
71
|
+
gem push *.gem
|
72
|
+
env:
|
73
|
+
GEM_HOST_API_KEY: "${{ secrets.RUBY_GEM_KEY }}"
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-
|
1
|
+
ruby-3.1.0
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.0
|
data/Gemfile
CHANGED
@@ -5,8 +5,8 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in ledger_sync-domains.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.
|
8
|
+
gem "rake", "~> 13.2"
|
9
9
|
|
10
|
-
gem "rspec", "~> 3.
|
10
|
+
gem "rspec", "~> 3.13"
|
11
11
|
|
12
|
-
gem "rubocop", "~> 1.
|
12
|
+
gem "rubocop", "~> 1.75"
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ledger_sync-domains (1.
|
5
|
-
ledger_sync (~>
|
4
|
+
ledger_sync-domains (1.4.0)
|
5
|
+
ledger_sync (~> 3.0.0)
|
6
|
+
openssl (~> 3.1.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -14,12 +15,12 @@ GEM
|
|
14
15
|
i18n (>= 1.6, < 2)
|
15
16
|
minitest (>= 5.1)
|
16
17
|
tzinfo (~> 2.0)
|
17
|
-
ast (2.4.
|
18
|
-
byebug (
|
18
|
+
ast (2.4.3)
|
19
|
+
byebug (12.0.0)
|
19
20
|
colorize (0.8.1)
|
20
|
-
concurrent-ruby (1.
|
21
|
-
diff-lcs (1.
|
22
|
-
dotenv (
|
21
|
+
concurrent-ruby (1.3.5)
|
22
|
+
diff-lcs (1.6.0)
|
23
|
+
dotenv (3.1.8)
|
23
24
|
dry-configurable (0.15.0)
|
24
25
|
concurrent-ruby (~> 1.0)
|
25
26
|
dry-core (~> 0.6)
|
@@ -52,8 +53,8 @@ GEM
|
|
52
53
|
dry-core (~> 0.5, >= 0.5)
|
53
54
|
dry-initializer (~> 3.0)
|
54
55
|
dry-schema (~> 1.8, >= 1.8.0)
|
55
|
-
factory_bot (6.
|
56
|
-
activesupport (>=
|
56
|
+
factory_bot (6.5.1)
|
57
|
+
activesupport (>= 6.1.0)
|
57
58
|
faraday (1.10.0)
|
58
59
|
faraday-em_http (~> 1.0)
|
59
60
|
faraday-em_synchrony (~> 1.0)
|
@@ -83,10 +84,11 @@ GEM
|
|
83
84
|
faraday (~> 1.0)
|
84
85
|
fingerprintable (1.2.1)
|
85
86
|
colorize
|
86
|
-
i18n (1.
|
87
|
+
i18n (1.14.7)
|
87
88
|
concurrent-ruby (~> 1.0)
|
88
|
-
|
89
|
-
|
89
|
+
json (2.10.2)
|
90
|
+
language_server-protocol (3.17.0.4)
|
91
|
+
ledger_sync (3.0.0)
|
90
92
|
activemodel
|
91
93
|
dotenv
|
92
94
|
dry-schema
|
@@ -96,68 +98,76 @@ GEM
|
|
96
98
|
faraday_middleware
|
97
99
|
fingerprintable (>= 1.2.1)
|
98
100
|
nokogiri
|
99
|
-
openssl (
|
101
|
+
openssl (> 2.2.0)
|
100
102
|
pd_ruby
|
101
103
|
rack (>= 2.2.3)
|
102
104
|
rainbow (~> 3.0)
|
103
105
|
resonad
|
104
106
|
simply_serializable (>= 1.5.1)
|
105
|
-
|
106
|
-
|
107
|
+
lint_roller (1.1.0)
|
108
|
+
mini_portile2 (2.8.9)
|
109
|
+
minitest (5.25.5)
|
107
110
|
multipart-post (2.2.3)
|
108
|
-
nokogiri (1.
|
109
|
-
mini_portile2 (~> 2.8.
|
111
|
+
nokogiri (1.18.8)
|
112
|
+
mini_portile2 (~> 2.8.2)
|
110
113
|
racc (~> 1.4)
|
111
|
-
openssl (
|
112
|
-
|
113
|
-
|
114
|
-
parser (3.0.3.2)
|
114
|
+
openssl (3.1.1)
|
115
|
+
parallel (1.27.0)
|
116
|
+
parser (3.3.8.0)
|
115
117
|
ast (~> 2.4.1)
|
118
|
+
racc
|
116
119
|
pd_ruby (0.2.3)
|
117
120
|
colorize
|
118
|
-
|
121
|
+
prism (1.4.0)
|
122
|
+
racc (1.8.1)
|
119
123
|
rack (2.2.4)
|
120
|
-
rainbow (3.
|
121
|
-
rake (13.
|
122
|
-
regexp_parser (2.
|
124
|
+
rainbow (3.1.1)
|
125
|
+
rake (13.2.1)
|
126
|
+
regexp_parser (2.10.0)
|
123
127
|
resonad (1.4.0)
|
124
|
-
|
125
|
-
|
126
|
-
rspec-
|
127
|
-
rspec-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
rspec-expectations (3.10.1)
|
128
|
+
rspec (3.13.0)
|
129
|
+
rspec-core (~> 3.13.0)
|
130
|
+
rspec-expectations (~> 3.13.0)
|
131
|
+
rspec-mocks (~> 3.13.0)
|
132
|
+
rspec-core (3.13.3)
|
133
|
+
rspec-support (~> 3.13.0)
|
134
|
+
rspec-expectations (3.13.3)
|
132
135
|
diff-lcs (>= 1.2.0, < 2.0)
|
133
|
-
rspec-support (~> 3.
|
134
|
-
rspec-mocks (3.
|
136
|
+
rspec-support (~> 3.13.0)
|
137
|
+
rspec-mocks (3.13.2)
|
135
138
|
diff-lcs (>= 1.2.0, < 2.0)
|
136
|
-
rspec-support (~> 3.
|
137
|
-
rspec-support (3.
|
138
|
-
rubocop (1.
|
139
|
+
rspec-support (~> 3.13.0)
|
140
|
+
rspec-support (3.13.2)
|
141
|
+
rubocop (1.75.2)
|
142
|
+
json (~> 2.3)
|
143
|
+
language_server-protocol (~> 3.17.0.2)
|
144
|
+
lint_roller (~> 1.1.0)
|
139
145
|
parallel (~> 1.10)
|
140
|
-
parser (>= 3.
|
146
|
+
parser (>= 3.3.0.2)
|
141
147
|
rainbow (>= 2.2.2, < 4.0)
|
142
|
-
regexp_parser (>=
|
143
|
-
|
144
|
-
rubocop-ast (>= 1.12.0, < 2.0)
|
148
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
149
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
145
150
|
ruby-progressbar (~> 1.7)
|
146
|
-
unicode-display_width (>=
|
147
|
-
rubocop-ast (1.
|
148
|
-
parser (>= 3.
|
149
|
-
|
151
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
152
|
+
rubocop-ast (1.44.1)
|
153
|
+
parser (>= 3.3.7.2)
|
154
|
+
prism (~> 1.4)
|
155
|
+
ruby-progressbar (1.13.0)
|
150
156
|
ruby2_keywords (0.0.5)
|
151
157
|
simply_serializable (1.5.1)
|
152
158
|
fingerprintable (>= 1.2.1)
|
153
|
-
tzinfo (2.0.
|
159
|
+
tzinfo (2.0.6)
|
154
160
|
concurrent-ruby (~> 1.0)
|
155
|
-
unicode-display_width (
|
161
|
+
unicode-display_width (3.1.4)
|
162
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
163
|
+
unicode-emoji (4.0.4)
|
156
164
|
|
157
165
|
PLATFORMS
|
158
166
|
aarch64-linux
|
159
167
|
arm64-darwin-21
|
168
|
+
arm64-darwin-24
|
160
169
|
x86_64-darwin-22
|
170
|
+
x86_64-darwin-24
|
161
171
|
x86_64-linux
|
162
172
|
|
163
173
|
DEPENDENCIES
|
@@ -165,9 +175,9 @@ DEPENDENCIES
|
|
165
175
|
dotenv
|
166
176
|
factory_bot
|
167
177
|
ledger_sync-domains!
|
168
|
-
rake (~> 13.
|
169
|
-
rspec (~> 3.
|
170
|
-
rubocop (~> 1.
|
178
|
+
rake (~> 13.2)
|
179
|
+
rspec (~> 3.13)
|
180
|
+
rubocop (~> 1.75)
|
171
181
|
|
172
182
|
BUNDLED WITH
|
173
183
|
2.4.1
|
data/README.md
CHANGED
@@ -269,7 +269,7 @@ module Auth
|
|
269
269
|
end
|
270
270
|
```
|
271
271
|
|
272
|
-
When performing an operation there are series of guards. First one validates if operation is allowed to be executed. That means either it is not flagged as internal operation, or target domain is same domain as module operation is defined in. If operation is not allowed to be executed, failure is returned with `LedgerSync::Domains::
|
272
|
+
When performing an operation there are series of guards. First one validates if operation is allowed to be executed. That means either it is not flagged as internal operation, or target domain is same domain as module operation is defined in. If operation is not allowed to be executed, failure is returned with `LedgerSync::Domains::OperationError` error.
|
273
273
|
|
274
274
|
### Cross-domain relationships
|
275
275
|
|
data/ledger_sync-domains.gemspec
CHANGED
@@ -6,19 +6,19 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = 'ledger_sync-domains'
|
7
7
|
spec.version = LedgerSync::Domains::VERSION
|
8
8
|
spec.authors = ['Jozef Vaclavik']
|
9
|
-
spec.email = ['jozef@
|
9
|
+
spec.email = ['jozef@hey.com']
|
10
10
|
|
11
11
|
spec.summary = 'LedgerSync for Domains/Engines'
|
12
12
|
spec.description = 'Use LedgerSync Operations and Serializers for cross-domain communication.'
|
13
|
-
spec.homepage = 'https://
|
13
|
+
spec.homepage = 'https://www.ledgersync.dev/'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new('>=
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.1.0')
|
16
16
|
|
17
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
18
|
|
19
19
|
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
-
spec.metadata['source_code_uri'] = 'https://github.com/
|
21
|
-
spec.metadata['changelog_uri'] = 'https://github.com/
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/LedgerSync/ledger_sync-domains'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LedgerSync/ledger_sync-domains/blob/main/CHANGELOG.md'
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -29,7 +29,8 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ['lib']
|
31
31
|
|
32
|
-
spec.add_dependency 'ledger_sync', '~>
|
32
|
+
spec.add_dependency 'ledger_sync', '~> 3.0.0'
|
33
|
+
spec.add_dependency 'openssl', '~> 3.1.0'
|
33
34
|
spec.add_development_dependency 'byebug'
|
34
35
|
spec.add_development_dependency 'dotenv'
|
35
36
|
spec.add_development_dependency 'factory_bot'
|
@@ -12,8 +12,7 @@ module LedgerSync
|
|
12
12
|
required(:model_name).filled(:string)
|
13
13
|
required(:id).filled(:integer)
|
14
14
|
required(:event).value(:string)
|
15
|
-
required(:attrs).maybe(
|
16
|
-
required(:attrs).maybe(:array)
|
15
|
+
required(:attrs).maybe(%i[hash array])
|
17
16
|
required(:limit).value(:hash)
|
18
17
|
end
|
19
18
|
end
|
@@ -9,7 +9,47 @@ end
|
|
9
9
|
|
10
10
|
module LedgerSync
|
11
11
|
module Domains
|
12
|
-
|
12
|
+
module ResultBase
|
13
|
+
module HelperMethods
|
14
|
+
def Success(value = nil, *args, **keywords) # rubocop:disable Naming/MethodName
|
15
|
+
self::Success.new(value, *args, **keywords)
|
16
|
+
end
|
17
|
+
|
18
|
+
def Failure(error = nil, *args, **keywords) # rubocop:disable Naming/MethodName
|
19
|
+
self::Failure.new(error, *args, **keywords)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.included(base)
|
24
|
+
base.const_set('Success', Class.new(Resonad::Success))
|
25
|
+
base::Success.include base::ResultTypeBase if base.const_defined?('ResultTypeBase')
|
26
|
+
|
27
|
+
base.const_set('Failure', Class.new(Resonad::Failure))
|
28
|
+
base::Failure.include base::ResultTypeBase if base.const_defined?('ResultTypeBase')
|
29
|
+
|
30
|
+
base.extend HelperMethods
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class OperationResult
|
35
|
+
module ResultTypeBase
|
36
|
+
attr_reader :operation, :meta
|
37
|
+
|
38
|
+
def self.included(base)
|
39
|
+
base.class_eval do
|
40
|
+
simply_serialize only: %i[operation meta]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(*args, **keywords)
|
45
|
+
@operation = keywords.fetch(:operation)
|
46
|
+
@meta = keywords[:meta]
|
47
|
+
super(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
include ResultBase
|
52
|
+
end
|
13
53
|
|
14
54
|
class Operation
|
15
55
|
class OperationResult
|
@@ -60,11 +100,14 @@ module LedgerSync
|
|
60
100
|
|
61
101
|
attr_reader :params, :result
|
62
102
|
|
63
|
-
def initialize(domain
|
103
|
+
def initialize(domain: nil, **params)
|
64
104
|
@domain = domain
|
65
|
-
@serializer = serializer
|
66
105
|
@params = params
|
67
106
|
@result = nil
|
107
|
+
|
108
|
+
validation_contract_class.new.schema.key_map.each do |key|
|
109
|
+
define_singleton_method(key.name) { params[key.name.to_sym] }
|
110
|
+
end
|
68
111
|
end
|
69
112
|
|
70
113
|
def perform # rubocop:disable Metrics/MethodLength
|
@@ -79,23 +122,32 @@ module LedgerSync
|
|
79
122
|
|
80
123
|
if performed?
|
81
124
|
return failure(
|
82
|
-
LedgerSync::
|
125
|
+
LedgerSync::Domains::PerformedOperationError.new(
|
83
126
|
operation: self
|
84
127
|
)
|
85
128
|
)
|
86
129
|
end
|
87
130
|
|
88
|
-
|
131
|
+
unless valid?
|
132
|
+
return failure(
|
133
|
+
LedgerSync::Domains::ValidationError.new(
|
134
|
+
operation: self,
|
135
|
+
errors: errors
|
136
|
+
)
|
137
|
+
)
|
138
|
+
end
|
89
139
|
|
90
|
-
|
91
|
-
operate
|
140
|
+
begin
|
141
|
+
@result = operate
|
92
142
|
rescue LedgerSync::Error => e
|
93
|
-
failure(e)
|
143
|
+
@result = failure(e)
|
94
144
|
rescue StandardError => e
|
95
|
-
failure(e)
|
145
|
+
@result = failure(e)
|
96
146
|
ensure
|
97
147
|
@performed = true
|
98
148
|
end
|
149
|
+
|
150
|
+
@result
|
99
151
|
end
|
100
152
|
|
101
153
|
def allowed?
|
@@ -109,26 +161,27 @@ module LedgerSync
|
|
109
161
|
end
|
110
162
|
|
111
163
|
def serialize(resource:)
|
112
|
-
serializer_for(resource: resource)
|
164
|
+
serializer = serializer_for(resource: resource)
|
165
|
+
return resource unless serializer
|
166
|
+
|
167
|
+
serializer_for(resource: resource).new.serialize(resource: resource)
|
113
168
|
end
|
114
169
|
|
115
170
|
def serializer_for(resource:)
|
116
|
-
|
171
|
+
return unless Object.const_defined?(serializer_class_name_for(resource: resource))
|
172
|
+
|
173
|
+
Object.const_get(serializer_class_name_for(resource: resource))
|
117
174
|
end
|
118
175
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
].join('::')
|
125
|
-
)
|
176
|
+
def serializer_class_name_for(resource:)
|
177
|
+
[
|
178
|
+
serializer_module_for(resource: resource),
|
179
|
+
"#{domain}Serializer"
|
180
|
+
].join('::')
|
126
181
|
end
|
127
182
|
|
128
183
|
def serializer_module_for(resource:)
|
129
|
-
(
|
130
|
-
resource.class.try(:serializer_module) || resource.class
|
131
|
-
).to_s.pluralize
|
184
|
+
resource.class.try(:serializer_module) || resource.class.name.pluralize
|
132
185
|
end
|
133
186
|
|
134
187
|
def domain
|
@@ -143,8 +196,8 @@ module LedgerSync
|
|
143
196
|
|
144
197
|
# Results
|
145
198
|
|
146
|
-
def
|
147
|
-
|
199
|
+
def success?
|
200
|
+
result.success?
|
148
201
|
end
|
149
202
|
|
150
203
|
def failure?
|
@@ -152,12 +205,31 @@ module LedgerSync
|
|
152
205
|
end
|
153
206
|
|
154
207
|
def success(value, meta: nil)
|
155
|
-
@result = OperationResult.Success(
|
208
|
+
@result = LedgerSync::Domains::OperationResult.Success(
|
209
|
+
deep_serialize(value),
|
210
|
+
operation: self, meta: meta
|
211
|
+
)
|
212
|
+
success_callback
|
213
|
+
@result
|
214
|
+
end
|
215
|
+
|
216
|
+
def failure(error)
|
217
|
+
unless error.is_a?(Exception)
|
218
|
+
error = LedgerSync::Domains::UnspecifiedError.new(operation: self, error: error)
|
219
|
+
end
|
220
|
+
|
221
|
+
@result = LedgerSync::Domains::OperationResult.Failure(error, operation: self)
|
222
|
+
failure_callback
|
223
|
+
@result
|
156
224
|
end
|
157
225
|
|
226
|
+
def success_callback; end
|
227
|
+
|
228
|
+
def failure_callback; end
|
229
|
+
|
158
230
|
def deep_serialize(value)
|
159
231
|
case value
|
160
|
-
when ActiveRecord::Base
|
232
|
+
when ActiveRecord::Base, LedgerSync::Resource
|
161
233
|
serialize(resource: value)
|
162
234
|
when Hash
|
163
235
|
value.transform_values { deep_serialize(_1) }
|
@@ -168,10 +240,6 @@ module LedgerSync
|
|
168
240
|
end
|
169
241
|
end
|
170
242
|
|
171
|
-
def success?
|
172
|
-
result.success?
|
173
|
-
end
|
174
|
-
|
175
243
|
def valid?
|
176
244
|
validate.success?
|
177
245
|
end
|
@@ -184,10 +252,6 @@ module LedgerSync
|
|
184
252
|
end
|
185
253
|
|
186
254
|
def validation_contract_class
|
187
|
-
@validation_contract_class ||= inferred_validation_contract_class
|
188
|
-
end
|
189
|
-
|
190
|
-
def inferred_validation_contract_class
|
191
255
|
self.class.const_get('Contract')
|
192
256
|
end
|
193
257
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Domains
|
5
|
+
class Serializer < LedgerSync::Serializer
|
6
|
+
module Mixin
|
7
|
+
module ClassMethods
|
8
|
+
def serializer_module
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def domain_serializable(resource_attributes: nil, resource_references: [], resource_methods: []) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/MethodLength, Layout/LineLength
|
13
|
+
LedgerSync::Domains.domains.configs.each_value do |domain| # rubocop:disable Metrics/BlockLength
|
14
|
+
parent_name = name.split('::')[..-1]
|
15
|
+
module_name = parent_name.empty? ? Object : Object.const_get(parent_name.join('::'))
|
16
|
+
next if module_name.const_defined?("#{domain.name}Serializer")
|
17
|
+
|
18
|
+
default_attributes = new.attributes.map { |k, _| k.to_sym }
|
19
|
+
|
20
|
+
klass = Class.new(LedgerSync::Domains::Serializer) do
|
21
|
+
(resource_attributes || default_attributes).each { attribute _1 }
|
22
|
+
resource_methods.each { attribute _1 }
|
23
|
+
|
24
|
+
define_method :resource_references do
|
25
|
+
resource_references
|
26
|
+
end
|
27
|
+
|
28
|
+
def references_for(resource:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
29
|
+
return [] unless resource.class.respond_to?(:reflect_on_all_associations)
|
30
|
+
|
31
|
+
resource_name = self.class.name.split('::')
|
32
|
+
domain_name = resource_name.pop.gsub(/[^0-9a-z ]/i, '').gsub(/.*\KSerializer/, '')
|
33
|
+
|
34
|
+
resource.class.reflect_on_all_associations.map do |association|
|
35
|
+
next unless resource_references.include?(association.name)
|
36
|
+
unless Object.const_defined?("#{association.klass.name}::#{domain_name}Serializer") # rubocop:disable Layout/LineLength
|
37
|
+
next
|
38
|
+
end
|
39
|
+
|
40
|
+
serializer = Object.const_get("#{association.klass.name}::#{domain_name}Serializer") # rubocop:disable Layout/LineLength
|
41
|
+
|
42
|
+
if association.belongs_to? || association.has_one?
|
43
|
+
LedgerSync::Serialization::SerializerAttribute.new(
|
44
|
+
hash_attribute: association.name,
|
45
|
+
resource_attribute: association.name,
|
46
|
+
type: Serialization::Type::SerializerReferencesOneType.new(
|
47
|
+
serializer: serializer
|
48
|
+
)
|
49
|
+
)
|
50
|
+
else
|
51
|
+
LedgerSync::Serialization::SerializerAttribute.new(
|
52
|
+
hash_attribute: association.name,
|
53
|
+
resource_attribute: association.name,
|
54
|
+
type: Serialization::Type::SerializerReferencesManyType.new(
|
55
|
+
serializer: serializer
|
56
|
+
)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end.compact
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module_name.const_set("#{domain.name}Serializer", klass)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.included(base)
|
69
|
+
base.extend ClassMethods
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'ostruct'
|
3
4
|
require_relative 'query'
|
4
5
|
|
5
6
|
module LedgerSync
|
@@ -24,6 +25,7 @@ module LedgerSync
|
|
24
25
|
define_method('class_name') { resource.class.name }
|
25
26
|
define_method('model_name') { resource.model_name }
|
26
27
|
define_method('to_key') { resource.to_key }
|
28
|
+
define_method('_resource') { resource }
|
27
29
|
references.each do |args|
|
28
30
|
if args.type.instance_of?(LedgerSync::Serialization::Type::SerializerReferencesOneType) # rubocop:disable Layout/LineLength
|
29
31
|
define_method("#{args.hash_attribute}_id") do
|
@@ -5,33 +5,23 @@ require_relative 'serializer/struct'
|
|
5
5
|
module LedgerSync
|
6
6
|
module Domains
|
7
7
|
class Serializer < LedgerSync::Serializer
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
attributes.each_value do |attr|
|
13
|
-
if attr.references_many? || attr.references_one?
|
14
|
-
references.push(attr)
|
15
|
-
else
|
16
|
-
regular.push(attr)
|
17
|
-
end
|
8
|
+
def attributes_for(*)
|
9
|
+
self.class.attributes.values.select do |attr|
|
10
|
+
!attr.references_many? && !attr.references_one?
|
18
11
|
end
|
19
|
-
[regular, references]
|
20
12
|
end
|
21
13
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
14
|
+
def references_for(*)
|
15
|
+
self.class.attributes.values.select do |attr|
|
16
|
+
attr.references_many? || attr.references_one?
|
17
|
+
end
|
18
|
+
end
|
25
19
|
|
20
|
+
def serialize(args = {}) # rubocop:disable Metrics/MethodLength
|
21
|
+
resource = args.fetch(:resource)
|
26
22
|
ret = {}
|
27
23
|
|
28
|
-
|
29
|
-
regular.each do |serializer_attribute|
|
30
|
-
if (only_changes && !resource.attribute_changed?(serializer_attribute.resource_attribute)) || # rubocop:disable Layout/LineLength
|
31
|
-
(serializer_attribute.if_method.present? && !send(serializer_attribute.if_method, resource: resource)) # rubocop:disable Layout/LineLength
|
32
|
-
next
|
33
|
-
end
|
34
|
-
|
24
|
+
attributes_for(resource: resource).each do |serializer_attribute|
|
35
25
|
ret = LedgerSync::Util::HashHelpers.deep_merge(
|
36
26
|
hash_to_merge_into: ret,
|
37
27
|
other_hash: serializer_attribute.hash_attribute_hash_for(resource: resource)
|
@@ -39,7 +29,8 @@ module LedgerSync
|
|
39
29
|
end
|
40
30
|
Serializer::Struct.build(
|
41
31
|
ret, self.class.to_s,
|
42
|
-
resource: resource,
|
32
|
+
resource: resource,
|
33
|
+
references: references_for(resource: resource)
|
43
34
|
)
|
44
35
|
end
|
45
36
|
end
|
data/lib/ledger_sync/domains.rb
CHANGED
@@ -4,6 +4,7 @@ require 'ledger_sync'
|
|
4
4
|
require_relative 'domains/version'
|
5
5
|
require_relative 'domains/store'
|
6
6
|
require_relative 'domains/serializer'
|
7
|
+
require_relative 'domains/serializer/mixin'
|
7
8
|
require_relative 'domains/operation'
|
8
9
|
require_relative 'domains/operation/resource'
|
9
10
|
require_relative 'domains/operation/add'
|
@@ -16,6 +17,43 @@ require_relative 'domains/operation/update'
|
|
16
17
|
|
17
18
|
module LedgerSync
|
18
19
|
module Domains
|
20
|
+
class InternalOperationError < LedgerSync::Error::OperationError; end
|
21
|
+
|
22
|
+
class UnspecifiedError < LedgerSync::Error::OperationError
|
23
|
+
attr_reader :error
|
24
|
+
|
25
|
+
def initialize(operation:, error:)
|
26
|
+
@error = error
|
27
|
+
message = 'Operation failed with unraisable error. Please check your error.'
|
28
|
+
super(message: message, operation: operation)
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<#{self.class}: #{message} (errors: #{error.inspect})>"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class ValidationError < LedgerSync::Error::OperationError
|
37
|
+
attr_reader :errors
|
38
|
+
|
39
|
+
def initialize(operation:, errors:)
|
40
|
+
@errors = errors
|
41
|
+
message = 'Operation arguments are invalid. Please check your errors.'
|
42
|
+
super(message: message, operation: operation)
|
43
|
+
end
|
44
|
+
|
45
|
+
def inspect
|
46
|
+
"#<#{self.class}: #{message} (errors: #{errors.inspect})>"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class PerformedOperationError < LedgerSync::Error::OperationError
|
51
|
+
def initialize(operation:)
|
52
|
+
message = 'Operation has already been performed. Please check the result.'
|
53
|
+
super(message: message, operation: operation)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
19
57
|
def self.domains
|
20
58
|
@domains ||= LedgerSync::Domains::ConfigurationStore.new
|
21
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledger_sync-domains
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jozef Vaclavik
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ledger_sync
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: openssl
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.1.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: byebug
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,16 +82,18 @@ dependencies:
|
|
68
82
|
version: '0'
|
69
83
|
description: Use LedgerSync Operations and Serializers for cross-domain communication.
|
70
84
|
email:
|
71
|
-
- jozef@
|
85
|
+
- jozef@hey.com
|
72
86
|
executables: []
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
90
|
+
- ".github/dependabot.yml"
|
76
91
|
- ".github/workflows/ruby.yml"
|
77
92
|
- ".gitignore"
|
78
93
|
- ".rspec"
|
79
94
|
- ".rubocop.yml"
|
80
95
|
- ".ruby-version"
|
96
|
+
- ".tool-versions"
|
81
97
|
- CHANGELOG.md
|
82
98
|
- Gemfile
|
83
99
|
- Gemfile.lock
|
@@ -98,18 +114,19 @@ files:
|
|
98
114
|
- lib/ledger_sync/domains/operation/transition.rb
|
99
115
|
- lib/ledger_sync/domains/operation/update.rb
|
100
116
|
- lib/ledger_sync/domains/serializer.rb
|
117
|
+
- lib/ledger_sync/domains/serializer/mixin.rb
|
101
118
|
- lib/ledger_sync/domains/serializer/query.rb
|
102
119
|
- lib/ledger_sync/domains/serializer/struct.rb
|
103
120
|
- lib/ledger_sync/domains/store.rb
|
104
121
|
- lib/ledger_sync/domains/version.rb
|
105
|
-
homepage: https://
|
122
|
+
homepage: https://www.ledgersync.dev/
|
106
123
|
licenses:
|
107
124
|
- MIT
|
108
125
|
metadata:
|
109
|
-
homepage_uri: https://
|
110
|
-
source_code_uri: https://github.com/
|
111
|
-
changelog_uri: https://github.com/
|
112
|
-
post_install_message:
|
126
|
+
homepage_uri: https://www.ledgersync.dev/
|
127
|
+
source_code_uri: https://github.com/LedgerSync/ledger_sync-domains
|
128
|
+
changelog_uri: https://github.com/LedgerSync/ledger_sync-domains/blob/main/CHANGELOG.md
|
129
|
+
post_install_message:
|
113
130
|
rdoc_options: []
|
114
131
|
require_paths:
|
115
132
|
- lib
|
@@ -117,15 +134,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
134
|
requirements:
|
118
135
|
- - ">="
|
119
136
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
137
|
+
version: 3.1.0
|
121
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
139
|
requirements:
|
123
140
|
- - ">="
|
124
141
|
- !ruby/object:Gem::Version
|
125
142
|
version: '0'
|
126
143
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
128
|
-
signing_key:
|
144
|
+
rubygems_version: 3.3.3
|
145
|
+
signing_key:
|
129
146
|
specification_version: 4
|
130
147
|
summary: LedgerSync for Domains/Engines
|
131
148
|
test_files: []
|