ree_lib 1.0.98 → 1.0.100

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: 003ff6b57d8d5cee946819718f3ee0e374ecd658e7b36f396d675c0cb7ff65ad
4
- data.tar.gz: 61b4a4b961971cb19d8747eddee79142faa8134b1d2ab10cfb11daec9dd609f1
3
+ metadata.gz: 436304224d3a8af781f3fe62abf15b08d1843205b69a709bf2bbd441c31e246e
4
+ data.tar.gz: 2cdb3e48efa52939a43178dd9cae363cdbdbd1bef33509d359e13db0f6c1d017
5
5
  SHA512:
6
- metadata.gz: 96069d7ff2c87d9ebcb41e06750e24b8b0131d3e2c8dca411e6c9893a6b932fd22951d7faef7f9dd591d2ffac23595c83281c3367843c3fd049583bc57ea2ad3
7
- data.tar.gz: f98b9d6ad3784546f1351ee6db2954732f14020c2905d0dc15bf88c68bd6ba851a9a0560407eaf32f80ca58a52c1785418da0e402598755c94466dfddcad973d
6
+ metadata.gz: fe254bd39aaae6cd9c3c9d902dcdc48e3ae2c83d6fd1a868aedef47e80209fe6ff51f17c186d8ffe41d3d6e8486c24847ed7cf10670f5c1ac08756f508b5f712
7
+ data.tar.gz: c9e0f059aea5fd18804149e6e153f58934db60b57de76e3abd421a7f87fb4c28b8f5b8445523cc39a32df293c54584a6853020de12f4a0822a41049e55de218e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.98)
4
+ ree_lib (1.0.100)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -4,20 +4,56 @@ class ReeMapper::BuildMapperFactory
4
4
  include Ree::FnDSL
5
5
 
6
6
  fn :build_mapper_factory do
7
+ with_caller
7
8
  link 'ree_mapper/mapper', -> { Mapper }
8
9
  link 'ree_mapper/mapper_factory', -> { MapperFactory }
9
10
  link 'ree_mapper/mapper_strategy', -> { MapperStrategy }
10
11
  end
11
12
 
13
+ SEMAPHORE = Mutex.new
14
+
12
15
  contract(ArrayOf[MapperStrategy] => SubclassOf[MapperFactory])
13
16
  def call(strategies:)
14
- klass = Class.new(ReeMapper::MapperFactory)
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
15
39
 
16
- klass.instance_eval {
17
- @types = {}
18
- @wrappers = {}
19
- @strategies = strategies
20
- }
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?
21
57
 
22
58
  klass.register_type(:bool, ReeMapper::Bool.new)
23
59
  klass.register_type(:date_time, ReeMapper::DateTime.new)
@@ -30,7 +66,5 @@ class ReeMapper::BuildMapperFactory
30
66
  klass.register_type(:rational, ReeMapper::Rational.new)
31
67
 
32
68
  klass.register_wrapper(:array, ReeMapper::Array)
33
-
34
- klass
35
69
  end
36
70
  end
@@ -67,20 +67,13 @@ module ReeMapper
67
67
  factory = mod.instance_variable_get(:@mapper_factory)
68
68
  return factory if factory
69
69
 
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
70
+ self.build_mapper_factory(mod)
80
71
  end
81
72
 
82
73
  private
83
74
 
75
+ require_relative "./ree_mapper/functions/build_mapper_factory"
76
+
84
77
  def self.build_mapper_factory(mod)
85
78
  pckg_name = ReeString::Underscore.new.call(mod.name)
86
79
  factory_path = "#{pckg_name}/mapper_factory"
@@ -89,6 +82,9 @@ module ReeMapper
89
82
  return Object.const_get("#{mod.name}::MapperFactory").new
90
83
  end
91
84
 
85
+ factory = ReeMapper::BuildMapperFactory.new
86
+ factory.set_caller(mod).call(strategies: [])
87
+
92
88
  mapper_factory_klass = if package_file_exists?(factory_path) && mod != self
93
89
  package_require(factory_path)
94
90
  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,3 +1,12 @@
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
3
7
  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.98"
4
+ VERSION = "1.0.100"
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.98
4
+ version: 1.0.100
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-30 00:00:00.000000000 Z
11
+ date: 2024-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree