ree_lib 1.0.122 → 1.0.124

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: '03921ccbd7050911caf9c2ff781b825b5b0c68e3ac461c0ca03b5a857aa32be9'
4
- data.tar.gz: fe55c4f54db004e5603a198293b23feaef1538541b034137943d0dd990ebec39
3
+ metadata.gz: 8cd073c76921f49fde18af68ce44e502d48c2adeea9434761ca02b8f921be7d9
4
+ data.tar.gz: b9c8e03e18eae8e470cf2e97936fcb4f5d2a2c14b9355a23c8be4ad6727089b0
5
5
  SHA512:
6
- metadata.gz: 3b40ee304d8c9b72f81b80ce0e63687bad7f301ee4fd3f16bfa5628a61a3e5f47d796b1e5a197b93bc6c48fdfb90973a8512db1b283d4403770f4cfdcecb67ac
7
- data.tar.gz: 15de0a6eacc51bf19cb406ddfd9b0f016ab2720ed4d6a3c6d4b7da835961590b9ba6417a1931518227508b46a6a80e7a68f6de88e126d31f997be02e788492ad
6
+ metadata.gz: 138e4b4b6f3442b9cdcd299bab97d8bdfac891383acb3fcecb46a6e6ff4e3b5162db18bd1f820369b96b1852563400bcfff3c8002c4fbf2ce08f901d6fb6c2eb
7
+ data.tar.gz: b39e6736ae0d0a3385cf2720a472ecf0ea859926d054396b91e016389372fe2135c6fd65e5995e7224d83bcf926a243824d44e288ab44d8158ad870ff5556dd2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.122)
4
+ ree_lib (1.0.124)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -20,11 +20,11 @@ GEM
20
20
  bigdecimal (3.1.8)
21
21
  binding_of_caller (1.0.1)
22
22
  debug_inspector (>= 1.2.0)
23
- bootsnap (1.18.3)
23
+ bootsnap (1.18.4)
24
24
  msgpack (~> 1.2)
25
25
  commander (5.0.0)
26
26
  highline (~> 3.0.0)
27
- concurrent-ruby (1.3.3)
27
+ concurrent-ruby (1.3.4)
28
28
  crack (1.0.0)
29
29
  bigdecimal
30
30
  rexml
@@ -33,7 +33,7 @@ GEM
33
33
  diff-lcs (1.5.1)
34
34
  faker (3.4.2)
35
35
  i18n (>= 1.8.11, < 2)
36
- hashdiff (1.1.0)
36
+ hashdiff (1.1.1)
37
37
  highline (3.0.1)
38
38
  i18n (1.14.5)
39
39
  concurrent-ruby (~> 1.0)
@@ -45,19 +45,21 @@ GEM
45
45
  racc (~> 1.4)
46
46
  nokogiri (1.16.7-x86_64-linux)
47
47
  racc (~> 1.4)
48
- oj (3.16.4)
48
+ oj (3.16.5)
49
49
  bigdecimal (>= 3.0)
50
+ ostruct (>= 0.2)
51
+ ostruct (0.6.0)
50
52
  pg (1.5.7)
51
53
  public_suffix (6.0.1)
52
- racc (1.8.0)
54
+ racc (1.8.1)
53
55
  rack (3.1.7)
54
56
  rack-test (2.1.0)
55
57
  rack (>= 1.3)
56
58
  rainbow (3.1.1)
57
59
  rake (13.2.1)
58
- ree (1.0.43)
60
+ ree (1.0.46)
59
61
  commander (~> 5.0.0)
60
- rexml (3.3.2)
62
+ rexml (3.3.6)
61
63
  strscan
62
64
  roda (3.76.0)
63
65
  rack
@@ -68,7 +70,7 @@ GEM
68
70
  rspec-mocks (~> 3.13.0)
69
71
  rspec-core (3.13.0)
70
72
  rspec-support (~> 3.13.0)
71
- rspec-expectations (3.13.1)
73
+ rspec-expectations (3.13.2)
72
74
  diff-lcs (>= 1.2.0, < 2.0)
73
75
  rspec-support (~> 3.13.0)
74
76
  rspec-mocks (3.13.1)
@@ -233,7 +233,7 @@ module ReeDao
233
233
  foreign_key = foreign_key_from_dao(parent_dao)
234
234
  end
235
235
 
236
- root_ids = list.map(&:"#{primary_key}")
236
+ root_ids = list.map(&primary_key)
237
237
 
238
238
  scope ||= assoc_dao
239
239
  scope = scope.where(foreign_key => root_ids)
@@ -278,9 +278,12 @@ module ReeDao
278
278
  assoc_setter = if setter
279
279
  setter
280
280
  else
281
- "set_#{assoc_name}"
281
+ "#{assoc_name}="
282
282
  end
283
283
 
284
+ fallback_assoc_setter = nil
285
+ fallback_fk = nil
286
+
284
287
  list.each do |item|
285
288
  if setter && setter.is_a?(Proc)
286
289
  if to_dto
@@ -305,7 +308,7 @@ module ReeDao
305
308
  if reverse
306
309
  primary_key
307
310
  else
308
- foreign_key ? foreign_key : "#{assoc_name}_id"
311
+ foreign_key ? foreign_key : (fallback_fk ||= "#{assoc_name}_id")
309
312
  end
310
313
  end
311
314
 
@@ -321,10 +324,13 @@ module ReeDao
321
324
 
322
325
  value = [] if value.nil? && multiple
323
326
 
324
- begin
327
+ if item.respond_to?(assoc_setter)
325
328
  item.send(assoc_setter, value)
326
- rescue NoMethodError
327
- item.send("#{assoc_name}=", value)
329
+ else
330
+ item.send(
331
+ fallback_assoc_setter ||= "set_#{assoc_name}",
332
+ value
333
+ )
328
334
  end
329
335
  end
330
336
  end
@@ -13,14 +13,12 @@ RSpec.describe :agg do
13
13
  before :all do
14
14
  connection = build_pg_connection(ReeDaoAggTest::Db::DB_CONFIG)
15
15
 
16
- connection.drop_table(:organizations, cascade: true) if connection.table_exists?(:organizations)
17
- connection.drop_table(:users, cascade: true) if connection.table_exists?(:users)
18
- connection.drop_table(:user_passports, cascade: true) if connection.table_exists?(:user_passports)
19
- connection.drop_table(:books, cascade: true) if connection.table_exists?(:books)
20
- connection.drop_table(:chapters, cascade: true) if connection.table_exists?(:chapters)
21
- connection.drop_table(:avtorki, cascade: true) if connection.table_exists?(:avtorki)
22
- connection.drop_table(:reviews, cascade: true) if connection.table_exists?(:reviews)
23
- connection.drop_table(:review_authors, cascade: true) if connection.table_exists?(:review_authors)
16
+ [
17
+ :organizations, :users, :user_passports, :books, :chapters, :avtorki,
18
+ :reviews, :review_authors
19
+ ].each do |table|
20
+ connection.drop_table(table, cascade: true) if connection.table_exists?(table)
21
+ end
24
22
 
25
23
  connection.create_table :organizations do
26
24
  primary_key :id
@@ -866,7 +864,7 @@ RSpec.describe :agg do
866
864
 
867
865
  u = res[0]
868
866
  expect(u.books).to_not eq(nil)
869
- expect(u.books[0].chapters).to eq(nil)
867
+ expect(u.books[0].chapters).to eq([])
870
868
  expect(u.books[0].author).to eq(nil)
871
869
  expect(u.books[0].reviews).to_not eq(nil)
872
870
  expect(u.books[0].reviews[0].review_author).to_not eq(nil)
@@ -994,4 +992,4 @@ RSpec.describe :agg do
994
992
  ENV.delete('REE_DAO_SYNC_ASSOCIATIONS')
995
993
  }
996
994
  end
997
- end
995
+ end
@@ -44,31 +44,10 @@ class ReeDaoAggTest::Book
44
44
  field :user_id, Integer
45
45
  field :title, Nilor[String], default: nil
46
46
 
47
- field :author, Any
48
- end
49
-
50
- def set_chapters(chapters)
51
- @chapters = chapters; nil
52
- end
53
-
54
- def chapters
55
- @chapters
56
- end
57
-
58
- def set_author(author)
59
- @author = author
60
- end
47
+ field :author, Any, default: nil
61
48
 
62
- def author
63
- @author
64
- end
65
-
66
- def set_reviews(reviews)
67
- @reviews = reviews; nil
68
- end
69
-
70
- def reviews
71
- @reviews
49
+ collection :chapters, Any
50
+ collection :reviews, Any
72
51
  end
73
52
  end
74
53
 
@@ -87,7 +66,7 @@ class ReeDaoAggTest::User
87
66
  field :organization, Any, default: nil
88
67
  field :passport, Any, default: nil
89
68
  field :custom_field, Any, default: nil
90
-
69
+
91
70
  collection :movies, Any
92
71
  collection :videogames, Any
93
72
  collection :hobbies, Any
@@ -100,7 +79,7 @@ class ReeDaoAggTest::User
100
79
  end
101
80
 
102
81
  [
103
-
82
+
104
83
  ].each do |attr|
105
84
  define_method("set_#{attr}") do |*args|
106
85
  instance_variable_set("@#{attr}", *args)
@@ -509,4 +488,4 @@ class ReeDaoAggTest::ReviewAuthors
509
488
  integer :review_id
510
489
  string :name
511
490
  end
512
- end
491
+ end
@@ -1,6 +1,8 @@
1
1
  require_relative "./field_meta"
2
2
  require "date"
3
3
 
4
+ package_require("ree_object/functions/deep_dup")
5
+
4
6
  module ReeDto::DtoInstanceMethods
5
7
  include Ree::Contracts::Core
6
8
  include Ree::Contracts::ArgContracts
@@ -134,6 +136,22 @@ module ReeDto::DtoInstanceMethods
134
136
  end
135
137
  end
136
138
 
139
+ def initialize_copy(_other)
140
+ deep_dupper = ReeObject::DeepDup.new
141
+ @_attrs = deep_dupper.call(@_attrs)
142
+ @collections = deep_dupper.call(@collections) if defined?(@collections)
143
+ end
144
+
145
+ def initialize_dup(_other)
146
+ super
147
+ @changed_fields = nil
148
+ end
149
+
150
+ def initialize_clone(_other)
151
+ super
152
+ @changed_fields = @changed_fields.dup if defined?(@changed_fields)
153
+ end
154
+
137
155
  private
138
156
 
139
157
  def inspect_value(v)
@@ -182,4 +182,63 @@ RSpec.describe ReeDto::DSL do
182
182
  expect(dto.to_h).to eq({ string: "str", with_default: 1 })
183
183
  }
184
184
  end
185
+
186
+ describe "#dup" do
187
+ it {
188
+ dto = ReeDto::DtoClass.new(string: "str")
189
+ dto.string = +"changed"
190
+ expect(dto.changed_fields).to eq([:string])
191
+
192
+ dto.numbers = [1]
193
+
194
+ dup = dto.dup
195
+ expect(dup).to eq(dto)
196
+ expect(dup.object_id).not_to eq(dto.object_id)
197
+ expect(dup.changed_fields).to eq([])
198
+ expect(dup.numbers).to eq([1])
199
+
200
+ dup.numbers << 2
201
+ expect(dto.numbers).to eq([1])
202
+
203
+ dup.string.concat("2")
204
+ expect(dto.string).to eq("changed")
205
+
206
+ dup.string = "changed3"
207
+ expect(dto.string).to eq("changed")
208
+
209
+ dto.freeze
210
+ expect(dto.dup.frozen?).to eq(false)
211
+ }
212
+ end
213
+
214
+ describe "#clone" do
215
+ it {
216
+ dto = ReeDto::DtoClass.new(string: "str")
217
+ dto.string = "changed"
218
+ expect(dto.changed_fields).to eq([:string])
219
+
220
+ dto.numbers = [1]
221
+
222
+ clone = dto.clone
223
+ expect(clone).to eq(dto)
224
+ expect(clone.object_id).not_to eq(dto.object_id)
225
+ expect(clone.changed_fields).to eq([:string])
226
+ expect(clone.numbers).to eq([1])
227
+
228
+ clone.numbers << 2
229
+ expect(dto.numbers).to eq([1])
230
+
231
+ clone.string.concat("2")
232
+ expect(dto.string).to eq("changed")
233
+
234
+ clone.string = "changed3"
235
+ expect(dto.string).to eq("changed")
236
+
237
+ clone.with_default = 2
238
+ expect(dto.changed_fields).to eq([:string])
239
+
240
+ dto.freeze
241
+ expect(dto.clone.frozen?).to eq(true)
242
+ }
243
+ end
185
244
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.122"
4
+ VERSION = "1.0.124"
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.122
4
+ version: 1.0.124
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-08-22 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree