ledger_sync-domains 1.1.0 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61c31a4c2c548923425e509c754d43c9edfacf8ef8e2b2ce0a0f77c7c67acd74
4
- data.tar.gz: a305b2db6f2f4a040493c5b9da40662a76d9f9086404a76baa933eda5b0de88d
3
+ metadata.gz: 14d7f7a6ce94ba69c8e10a5aba3719bce8c2789fc9fdd9fdc599884a3391a32f
4
+ data.tar.gz: c5b7a3caee8948c730e0afe84eef573f686c0b6b4ca6efc5330a7893e8fdac61
5
5
  SHA512:
6
- metadata.gz: 66974930b8b9a27d57b004765de9562c48d751afe50cc971e0fc416ca52c0e0202d23061eba6bc17533130a7d147977b9e7eed8a0dff24fca9d48e2cced63f0d
7
- data.tar.gz: c0dbfcd42ecf473460084cf10cbf4b99d5dfbd45e9cac6ad05a107c006fd048712e37ac373dfd44475bc28ad20e804a5e2bf2eb817783170f6fbff13c15946fc
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.0)
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.14.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.3-x86_64-linux)
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 Relation
7
- def initialize(serializer:, resource:, attribute:)
8
- @query = resource.try(attribute)
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
- Relation.new(
112
+ Query.new(
113
113
  serializer: serializer,
114
- resource: resource,
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 'relation'
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
- Relation.const_get(
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
- # module_name.remove_const(struct_name) if module_name.const_defined?(struct_name)
57
- module_name.const_set(struct_name, Class.new(OpenStruct))
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),
@@ -2,6 +2,6 @@
2
2
 
3
3
  module LedgerSync
4
4
  module Domains
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.4'
6
6
  end
7
7
  end
@@ -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.0
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-02-25 00:00:00.000000000 Z
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/relation.rb
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