ree_lib 1.0.100 → 1.0.102

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 436304224d3a8af781f3fe62abf15b08d1843205b69a709bf2bbd441c31e246e
4
- data.tar.gz: 2cdb3e48efa52939a43178dd9cae363cdbdbd1bef33509d359e13db0f6c1d017
3
+ metadata.gz: 610961c832fe41c44de5956cddfdd9497c729af2446e44bcd3bcddacf68cf0bd
4
+ data.tar.gz: 31095b276ff9541504867a55ebd5d1edcd2bce13d60cd7c994b734863a14479d
5
5
  SHA512:
6
- metadata.gz: fe254bd39aaae6cd9c3c9d902dcdc48e3ae2c83d6fd1a868aedef47e80209fe6ff51f17c186d8ffe41d3d6e8486c24847ed7cf10670f5c1ac08756f508b5f712
7
- data.tar.gz: c9e0f059aea5fd18804149e6e153f58934db60b57de76e3abd421a7f87fb4c28b8f5b8445523cc39a32df293c54584a6853020de12f4a0822a41049e55de218e
6
+ metadata.gz: 44b5c42d66744b6e36c9c127162e846d91b0e5fe705e893fdeb0a45038f6e1777949ecf2b0d778c23db4592cd5f221b2d772ac2ab624e45f1de4fcc2d745f899
7
+ data.tar.gz: f7f437b8324816fdc02639570e64d1425ffeea53d71e8761178633b8826035062baf78ef891c4b96da96a380f2d2a9e92522ad13a800d10b112b165cc7419cf7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.100)
4
+ ree_lib (1.0.102)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -40,6 +40,13 @@
40
40
  "fn"
41
41
  ]
42
42
  },
43
+ {
44
+ "name": "agg_contract_for",
45
+ "schema": "packages/ree_dao/schemas/ree_dao/functions/agg_contract_for.schema.json",
46
+ "tags": [
47
+ "fn"
48
+ ]
49
+ },
43
50
  {
44
51
  "name": "build_connection",
45
52
  "schema": "packages/ree_dao/schemas/ree_dao/functions/build_connection.schema.json",
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ReeDao::AggContractFor
4
+ include Ree::FnDSL
5
+
6
+ fn :agg_contract_for do
7
+ target :class
8
+ with_caller
9
+ end
10
+
11
+ contract(Any => nil)
12
+ def call(klass)
13
+ get_caller.contract(
14
+ Or[Sequel::Dataset, ArrayOf[Integer], Integer, ArrayOf[klass]],
15
+ Ksplat[
16
+ only?: ArrayOf[Symbol],
17
+ except?: ArrayOf[Symbol],
18
+ RestKeys => Any
19
+ ] => ArrayOf[klass]
20
+ )
21
+
22
+ nil
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ {
2
+ "schema_type": "object",
3
+ "schema_version": "1.1",
4
+ "name": "agg_contract_for",
5
+ "path": "packages/ree_dao/package/ree_dao/functions/agg_contract_for.rb",
6
+ "mount_as": "fn",
7
+ "class": "ReeDao::AggContractFor",
8
+ "factory": null,
9
+ "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
13
+
14
+ ],
15
+ "return": "Any",
16
+ "args": [
17
+ {
18
+ "arg": "klass",
19
+ "arg_type": "req",
20
+ "type": "Any"
21
+ }
22
+ ]
23
+ }
24
+ ],
25
+ "links": [
26
+
27
+ ]
28
+ }
@@ -87,7 +87,7 @@ RSpec.describe :agg do
87
87
  include ReeDao::AggregateDSL
88
88
 
89
89
  aggregate :agg_users do
90
- link :users, from: :ree_dao_agg_test
90
+ link :users, from: :ree_dao_agg_test, import: -> { User }
91
91
  link :organizations_dao, from: :ree_dao_agg_test
92
92
  link :user_passports, from: :ree_dao_agg_test
93
93
  link :books, from: :ree_dao_agg_test
@@ -96,8 +96,10 @@ RSpec.describe :agg do
96
96
  link :reviews, from: :ree_dao_agg_test
97
97
  link :review_authors, from: :ree_dao_agg_test
98
98
  link :agg, from: :ree_dao
99
+ link :agg_contract_for, from: :ree_dao
99
100
  end
100
101
 
102
+ agg_contract_for User
101
103
  def call(ids_or_scope, **opts)
102
104
  agg(users, ids_or_scope, **opts) do |users_list|
103
105
  belongs_to :organization
@@ -4,56 +4,20 @@ class ReeMapper::BuildMapperFactory
4
4
  include Ree::FnDSL
5
5
 
6
6
  fn :build_mapper_factory do
7
- with_caller
8
7
  link 'ree_mapper/mapper', -> { Mapper }
9
8
  link 'ree_mapper/mapper_factory', -> { MapperFactory }
10
9
  link 'ree_mapper/mapper_strategy', -> { MapperStrategy }
11
10
  end
12
11
 
13
- SEMAPHORE = Mutex.new
14
-
15
12
  contract(ArrayOf[MapperStrategy] => SubclassOf[MapperFactory])
16
13
  def call(strategies:)
17
- mod = if get_caller.is_a?(Module)
18
- get_caller
19
- else
20
- name = get_caller.class.to_s.split("::").first
21
- Object.const_get(name)
22
- end
23
-
24
- klass = nil
25
-
26
- SEMAPHORE.synchronize do
27
- if klass = mod.instance_variable_get(:@mapper_factory)
28
- klass.instance_eval do
29
- @strategies = strategies
30
- end
31
- else
32
- klass = Class.new(ReeMapper::MapperFactory)
33
-
34
- klass.instance_eval do
35
- @types = {}
36
- @wrappers = {}
37
- @strategies = strategies
38
- end
14
+ klass = Class.new(ReeMapper::MapperFactory)
39
15
 
40
- mod.instance_variable_set(:@mapper_factory, klass)
41
- end
42
-
43
- register_default_types(klass)
44
- end
45
-
46
- klass
47
- end
48
-
49
- private
50
-
51
- def register_default_types(klass)
52
- types = klass.instance_variable_get(:@types)
53
- strategies = klass.instance_variable_get(:@strategies)
54
-
55
- return if !types.empty?
56
- return if strategies.empty?
16
+ klass.instance_eval {
17
+ @types = {}
18
+ @wrappers = {}
19
+ @strategies = strategies
20
+ }
57
21
 
58
22
  klass.register_type(:bool, ReeMapper::Bool.new)
59
23
  klass.register_type(:date_time, ReeMapper::DateTime.new)
@@ -66,5 +30,7 @@ class ReeMapper::BuildMapperFactory
66
30
  klass.register_type(:rational, ReeMapper::Rational.new)
67
31
 
68
32
  klass.register_wrapper(:array, ReeMapper::Array)
33
+
34
+ klass
69
35
  end
70
36
  end
@@ -67,13 +67,20 @@ module ReeMapper
67
67
  factory = mod.instance_variable_get(:@mapper_factory)
68
68
  return factory if factory
69
69
 
70
- self.build_mapper_factory(mod)
70
+ if !mod.instance_variable_get(:@mapper_semaphore)
71
+ mod.instance_variable_set(:@mapper_semaphore, Mutex.new)
72
+ end
73
+
74
+ mod.instance_variable_get(:@mapper_semaphore).synchronize do
75
+ factory = self.build_mapper_factory(mod)
76
+ mod.instance_variable_set(:@mapper_factory, factory)
77
+ end
78
+
79
+ factory
71
80
  end
72
81
 
73
82
  private
74
83
 
75
- require_relative "./ree_mapper/functions/build_mapper_factory"
76
-
77
84
  def self.build_mapper_factory(mod)
78
85
  pckg_name = ReeString::Underscore.new.call(mod.name)
79
86
  factory_path = "#{pckg_name}/mapper_factory"
@@ -82,9 +89,6 @@ module ReeMapper
82
89
  return Object.const_get("#{mod.name}::MapperFactory").new
83
90
  end
84
91
 
85
- factory = ReeMapper::BuildMapperFactory.new
86
- factory.set_caller(mod).call(strategies: [])
87
-
88
92
  mapper_factory_klass = if package_file_exists?(factory_path) && mod != self
89
93
  package_require(factory_path)
90
94
  Object.const_get("#{mod.name}::MapperFactory")
@@ -55,10 +55,10 @@ RSpec.describe ReeMapper::DSL do
55
55
  )
56
56
 
57
57
  expect(result).to eq({
58
- id: 1,
59
- title: 'Product',
60
- creator: {
61
- id: 1,
58
+ id: 1,
59
+ title: 'Product',
60
+ creator: {
61
+ id: 1,
62
62
  name: 'John',
63
63
  created_by: {
64
64
  id: 2,
@@ -1,12 +1,3 @@
1
1
  RSpec.configure do |config|
2
2
  config.extend Ree::RSpecLinkDSL
3
-
4
- config.before :each do
5
- reset_mapper_factory(self)
6
- end
7
3
  end
8
-
9
- def reset_mapper_factory(mod)
10
- mod = Object.const_get(self.class.to_s.split("::").first)
11
- mod.instance_variable_set(:@mapper_factory, nil)
12
- end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.100"
4
+ VERSION = "1.0.102"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.100
4
+ version: 1.0.102
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree
@@ -331,6 +331,7 @@ files:
331
331
  - lib/ree_lib/packages/ree_dao/package/ree_dao/dataset_extensions.rb
332
332
  - lib/ree_lib/packages/ree_dao/package/ree_dao/dsl.rb
333
333
  - lib/ree_lib/packages/ree_dao/package/ree_dao/functions/agg.rb
334
+ - lib/ree_lib/packages/ree_dao/package/ree_dao/functions/agg_contract_for.rb
334
335
  - lib/ree_lib/packages/ree_dao/package/ree_dao/functions/build_connection.rb
335
336
  - lib/ree_lib/packages/ree_dao/package/ree_dao/functions/build_dao.rb
336
337
  - lib/ree_lib/packages/ree_dao/package/ree_dao/functions/build_pg_connection.rb
@@ -343,6 +344,7 @@ files:
343
344
  - lib/ree_lib/packages/ree_dao/package/ree_dao/wrappers/pg_jsonb.rb
344
345
  - lib/ree_lib/packages/ree_dao/schemas/ree_dao/beans/connections.schema.json
345
346
  - lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/agg.schema.json
347
+ - lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/agg_contract_for.schema.json
346
348
  - lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/build_connection.schema.json
347
349
  - lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/build_dao.schema.json
348
350
  - lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/build_pg_connection.schema.json