ledger_sync-domains 1.1.0 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +3 -3
- data/lib/ledger_sync/domains/operation/query.rb +41 -0
- data/lib/ledger_sync/domains/operation.rb +3 -2
- data/lib/ledger_sync/domains/serializer/{relation.rb → query.rb} +5 -6
- data/lib/ledger_sync/domains/serializer/struct.rb +9 -5
- data/lib/ledger_sync/domains/version.rb +1 -1
- data/lib/ledger_sync/domains.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14d7f7a6ce94ba69c8e10a5aba3719bce8c2789fc9fdd9fdc599884a3391a32f
|
4
|
+
data.tar.gz: c5b7a3caee8948c730e0afe84eef573f686c0b6b4ca6efc5330a7893e8fdac61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c99ee3e2b9d0260aecda2f27663fb61c469957530d73813185c06d6bf0e2fa44941e07924a41f2a8b55697ae58580a1867f0ed289ed630ae0e0f1d202abe534
|
7
|
+
data.tar.gz: d933fa1ab6c3876a16890b93c7e33ff0eacbbfd08d219ac5bae93a368fc7d7317a9fc7bc9bfd47f2e0d3d79af3f2f92f3841ab1828557c239b3278c2dcc16603
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.1.4] - 2022-05-26
|
4
|
+
|
5
|
+
- Feature: Operation accepts custom serializer
|
6
|
+
|
7
|
+
## [1.1.3] - 2022-04-08
|
8
|
+
|
9
|
+
- Fix: Nasty typo
|
10
|
+
|
11
|
+
## [1.1.2] - 2022-04-08
|
12
|
+
|
13
|
+
- Fix: Disable previous definition warning
|
14
|
+
|
15
|
+
## [1.1.1] - 2022-03-17
|
16
|
+
|
17
|
+
- Feature: Refactor Relation into Query for use outside of relationships
|
18
|
+
- Feature: Add Query operation
|
19
|
+
|
3
20
|
## [1.1.0] - 2022-02-25
|
4
21
|
|
5
22
|
- Feature: Add and Update operations uses `data` params for setting model attributes
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ledger_sync-domains (1.1.
|
4
|
+
ledger_sync-domains (1.1.4)
|
5
5
|
ledger_sync (~> 2.3.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
concurrent-ruby (1.1.9)
|
21
21
|
diff-lcs (1.4.4)
|
22
22
|
dotenv (2.7.6)
|
23
|
-
dry-configurable (0.
|
23
|
+
dry-configurable (0.15.0)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
dry-core (~> 0.6)
|
26
26
|
dry-container (0.9.0)
|
@@ -103,7 +103,7 @@ GEM
|
|
103
103
|
simply_serializable (>= 1.5.1)
|
104
104
|
minitest (5.15.0)
|
105
105
|
multipart-post (2.1.1)
|
106
|
-
nokogiri (1.13.
|
106
|
+
nokogiri (1.13.6-x86_64-linux)
|
107
107
|
racc (~> 1.4)
|
108
108
|
openssl (2.2.1)
|
109
109
|
ipaddr
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../operation'
|
4
|
+
require_relative 'resource'
|
5
|
+
|
6
|
+
module LedgerSync
|
7
|
+
module Domains
|
8
|
+
class Operation
|
9
|
+
class Query < Resource
|
10
|
+
class Contract < LedgerSync::Ledgers::Contract
|
11
|
+
params do
|
12
|
+
required(:query).value(:hash)
|
13
|
+
required(:limit).value(:hash)
|
14
|
+
required(:includes).value(:array)
|
15
|
+
required(:order).value(:string)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def operate
|
22
|
+
success(query)
|
23
|
+
end
|
24
|
+
|
25
|
+
def resources
|
26
|
+
@resources ||= resource_class.where(params[:limit])
|
27
|
+
.where(params[:query])
|
28
|
+
.includes(params[:includes])
|
29
|
+
.order(params[:order])
|
30
|
+
end
|
31
|
+
|
32
|
+
def query
|
33
|
+
LedgerSync::Domains::Serializer::Query.new(
|
34
|
+
serializer: params[:serializer] || serializer_for(resource: resource_class.new),
|
35
|
+
query: resources
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -60,8 +60,9 @@ module LedgerSync
|
|
60
60
|
|
61
61
|
attr_reader :params, :result
|
62
62
|
|
63
|
-
def initialize(domain:, **params)
|
63
|
+
def initialize(domain:, serializer: nil, **params)
|
64
64
|
@domain = domain
|
65
|
+
@serializer = serializer
|
65
66
|
@params = params
|
66
67
|
@result = nil
|
67
68
|
end
|
@@ -112,7 +113,7 @@ module LedgerSync
|
|
112
113
|
end
|
113
114
|
|
114
115
|
def serializer_for(resource:)
|
115
|
-
serializer_class_for(resource: resource).new
|
116
|
+
@serializer || serializer_class_for(resource: resource).new
|
116
117
|
end
|
117
118
|
|
118
119
|
def serializer_class_for(resource:)
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module LedgerSync
|
4
4
|
module Domains
|
5
5
|
class Serializer < LedgerSync::Serializer
|
6
|
-
class
|
7
|
-
def initialize(serializer:,
|
8
|
-
@query =
|
6
|
+
class Query
|
7
|
+
def initialize(serializer:, query:)
|
8
|
+
@query = query
|
9
9
|
@serializer = serializer
|
10
10
|
end
|
11
11
|
|
@@ -109,10 +109,9 @@ module LedgerSync
|
|
109
109
|
|
110
110
|
class SerializerReferencesManyType
|
111
111
|
def proxy(serializer:, resource:, attribute:)
|
112
|
-
|
112
|
+
Query.new(
|
113
113
|
serializer: serializer,
|
114
|
-
|
115
|
-
attribute: attribute
|
114
|
+
query: resource.try(attribute)
|
116
115
|
)
|
117
116
|
end
|
118
117
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'query'
|
4
4
|
|
5
5
|
module LedgerSync
|
6
6
|
module Domains
|
@@ -23,7 +23,7 @@ module LedgerSync
|
|
23
23
|
define_method('to_hash') { hash }
|
24
24
|
references.each do |args|
|
25
25
|
define_method(args.hash_attribute) do
|
26
|
-
|
26
|
+
Query.const_get(
|
27
27
|
args.type.class.to_s.split('::').last
|
28
28
|
).new.proxy(
|
29
29
|
serializer: args.type.serializer.new,
|
@@ -53,9 +53,13 @@ module LedgerSync
|
|
53
53
|
class_name = name.pop.gsub(/[^0-9a-z ]/i, '').gsub(/.*\KSerializer/, '')
|
54
54
|
struct_name = "#{class_name}Struct"
|
55
55
|
module_name = name.empty? ? Object : Object.const_get(name.join('::'))
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
begin
|
57
|
+
v, $VERBOSE = $VERBOSE, v
|
58
|
+
# module_name.remove_const(struct_name) if module_name.const_defined?(struct_name)
|
59
|
+
module_name.const_set(struct_name, Class.new(OpenStruct))
|
60
|
+
ensure
|
61
|
+
$VERBOSE = v
|
62
|
+
end
|
59
63
|
klass.with_lazy_references(
|
60
64
|
hash,
|
61
65
|
struct_class: module_name.const_get(struct_name),
|
data/lib/ledger_sync/domains.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'domains/operation'
|
|
8
8
|
require_relative 'domains/operation/resource'
|
9
9
|
require_relative 'domains/operation/add'
|
10
10
|
require_relative 'domains/operation/find'
|
11
|
+
require_relative 'domains/operation/query'
|
11
12
|
require_relative 'domains/operation/remove'
|
12
13
|
require_relative 'domains/operation/search'
|
13
14
|
require_relative 'domains/operation/transition'
|
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.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jozef Vaclavik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ledger_sync
|
@@ -91,13 +91,14 @@ files:
|
|
91
91
|
- lib/ledger_sync/domains/operation.rb
|
92
92
|
- lib/ledger_sync/domains/operation/add.rb
|
93
93
|
- lib/ledger_sync/domains/operation/find.rb
|
94
|
+
- lib/ledger_sync/domains/operation/query.rb
|
94
95
|
- lib/ledger_sync/domains/operation/remove.rb
|
95
96
|
- lib/ledger_sync/domains/operation/resource.rb
|
96
97
|
- lib/ledger_sync/domains/operation/search.rb
|
97
98
|
- lib/ledger_sync/domains/operation/transition.rb
|
98
99
|
- lib/ledger_sync/domains/operation/update.rb
|
99
100
|
- lib/ledger_sync/domains/serializer.rb
|
100
|
-
- lib/ledger_sync/domains/serializer/
|
101
|
+
- lib/ledger_sync/domains/serializer/query.rb
|
101
102
|
- lib/ledger_sync/domains/serializer/struct.rb
|
102
103
|
- lib/ledger_sync/domains/store.rb
|
103
104
|
- lib/ledger_sync/domains/version.rb
|