ree_lib 1.0.119 → 1.0.121

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: f74fddaac7132110d9917614ea455fff6eb718eaf8ed969fc897995346d915b3
4
- data.tar.gz: 52d6b3e4461d320f8fd3affdb37b46cfe1ebb56d9fbc4879020021bbb3515746
3
+ metadata.gz: 381666058a003165d365519531e3341ecc42c2b4756be1152651914bdd4f0419
4
+ data.tar.gz: 9e1648ebd630847fbbe7acd75bac9e5c876cfeb8cfcb065d80a85ac798442eb7
5
5
  SHA512:
6
- metadata.gz: 9c66a59c59055abdd1bfa11358f0e9b0d645b45e2fa2d7b0d3bbdbed8e545763bb650de824baf7e7a484999cff28106e0be102a0f7c2543579c6b6f404eb9766
7
- data.tar.gz: 43bb3573292d9c2392aa8964d4a0640c0eee93be1aac867fcfa029e594b9096df78d77736c0b9b43900e3828f99b353b58051e2e942165f572429c54f6263468
6
+ metadata.gz: 3138793f0e16c9e8dbb7152685d1aacaa411f8eb9c8c95b0ff571b609c3297a583361cfa3571e8a732206be323c9ea70e4df7c34b2c88f705f0af4ef5effacbe
7
+ data.tar.gz: 554d74d6c446a0628a803275e1841d35ad78bf192ba1a35bcd7105995185a244a5f14be0eab17d81484242e20d329414370c78b819afe2c0ff7a3c71dcd8a1a9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.119)
4
+ ree_lib (1.0.121)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ class ReeDao::DtoContract
3
+ extend Ree::Contracts::Truncatable
4
+
5
+ def self.valid?(obj)
6
+ obj.class.ancestors.include?(ReeDto::DSL)
7
+ end
8
+
9
+ def self.to_s
10
+ "ReeDto::Dto"
11
+ end
12
+
13
+ def self.message(value, name, lvl = 1)
14
+ "expected #{to_s}, got => #{truncate(value.inspect)}"
15
+ end
16
+ end
@@ -97,6 +97,7 @@ module ReeDao
97
97
  end
98
98
 
99
99
  key = insert_conflict(conflict_opts).insert(raw)
100
+ return if key.nil?
100
101
 
101
102
  set_entity_primary_key(entity, raw, key)
102
103
  set_persistence_state(entity, raw)
@@ -251,7 +252,16 @@ module ReeDao
251
252
 
252
253
  def extract_changes(entity, hash)
253
254
  if is_ree_dto?(entity)
254
- hash.slice(*entity.changed_fields)
255
+ result = {}
256
+ changed = entity.changed_fields
257
+
258
+ hash.each do |k, v|
259
+ if changed.include?(k) || v.respond_to?(:each)
260
+ result[k] = v
261
+ end
262
+ end
263
+
264
+ result
255
265
  else
256
266
  return hash unless entity.instance_variable_defined?(PERSISTENCE_STATE_VARIABLE)
257
267
  changes = {}
@@ -7,11 +7,12 @@ class ReeDao::Agg
7
7
  link "ree_dao/associations", -> { Associations }
8
8
  link "ree_dao/contract/dao_dataset_contract", -> { DaoDatasetContract }
9
9
  link "ree_dao/contract/entity_contract", -> { EntityContract }
10
+ link "ree_dao/contract/dto_contract", -> { DtoContract }
10
11
  end
11
12
 
12
13
  contract(
13
14
  DaoDatasetContract,
14
- Or[Sequel::Dataset, ArrayOf[Integer], ArrayOf[EntityContract], Integer],
15
+ Or[Sequel::Dataset, ArrayOf[Integer], ArrayOf[EntityContract], ArrayOf[DtoContract], Integer],
15
16
  Ksplat[
16
17
  only?: ArrayOf[Symbol],
17
18
  except?: ArrayOf[Symbol],
@@ -181,7 +181,7 @@ RSpec.describe :agg do
181
181
  {
182
182
  to_dto: -> (book) { ReeDaoAggTest::BookDto.new(book) },
183
183
  setter: -> (item, child_index) {
184
- item.set_books(child_index[item.id] || [])
184
+ item.books = child_index[item.id] || []
185
185
  }
186
186
  }
187
187
  end
@@ -286,7 +286,7 @@ RSpec.describe :agg do
286
286
  {
287
287
  setter: -> (item, items_index) {
288
288
  b = items_index[item.id].each { |b| b.title = "Changed" }
289
- item.set_books(b)
289
+ item.books = b
290
290
  }
291
291
  }
292
292
  end
@@ -990,7 +990,7 @@ RSpec.describe :agg do
990
990
  expect(user).to receive(:some_field=).with(:some_value)
991
991
 
992
992
  ENV['REE_DAO_SYNC_ASSOCIATIONS'] = "true"
993
- res = agg_users.([user])
993
+ agg_users.([user])
994
994
  ENV.delete('REE_DAO_SYNC_ASSOCIATIONS')
995
995
  }
996
996
  end
@@ -5,6 +5,7 @@ module ReeDaoAggTest
5
5
 
6
6
  package do
7
7
  depends_on :ree_dao
8
+ depends_on :ree_dto
8
9
  depends_on :ree_array
9
10
  depends_on :ree_string
10
11
  depends_on :ree_hash
@@ -36,13 +37,15 @@ class ReeDaoAggTest::Db
36
37
  end
37
38
 
38
39
  class ReeDaoAggTest::Book
39
- include ReeDto::EntityDSL
40
+ include ReeDto::DSL
40
41
 
41
- properties(
42
- id: Nilor[Integer],
43
- user_id: Integer,
44
- title: Nilor[String]
45
- )
42
+ build_dto do
43
+ field :id, Nilor[Integer], default: nil
44
+ field :user_id, Integer
45
+ field :title, Nilor[String], default: nil
46
+
47
+ field :author, Any
48
+ end
46
49
 
47
50
  def set_chapters(chapters)
48
51
  @chapters = chapters; nil
@@ -67,71 +70,37 @@ class ReeDaoAggTest::Book
67
70
  def reviews
68
71
  @reviews
69
72
  end
70
-
71
- def title=(t)
72
- @title = t
73
- end
74
-
75
- attr_accessor :title, :user_id
76
73
  end
77
74
 
78
75
  class ReeDaoAggTest::BookDto < SimpleDelegator
79
76
  end
80
77
 
81
78
  class ReeDaoAggTest::User
82
- include ReeDto::EntityDSL
83
-
84
- properties(
85
- id: Nilor[Integer],
86
- name: String,
87
- age: Integer,
88
- organization_id: Integer
89
- )
90
-
91
- def set_organization(org)
92
- @organization = org
93
- end
94
-
95
- def organization
96
- @organization
97
- end
98
-
99
- def set_passport(passport)
100
- @passport = passport
101
- end
102
-
103
- def passport
104
- @passport
105
- end
106
-
107
- def books
108
- @books
109
- end
110
-
111
- def set_active_books(books)
112
- @active_books = books
113
- end
114
-
115
- def active_books
116
- @active_books
117
- end
118
-
119
- contract(ArrayOf[ReeDaoAggTest::Book] => nil)
120
- def set_books(books)
121
- @books = books; nil
79
+ include ReeDto::DSL
80
+
81
+ build_dto do
82
+ field :id, Nilor[Integer], default: nil
83
+ field :name, String
84
+ field :age, Integer
85
+ field :organization_id, Integer
86
+
87
+ field :organization, Any, default: nil
88
+ field :passport, Any, default: nil
89
+ field :custom_field, Any, default: nil
90
+
91
+ collection :movies, Any
92
+ collection :videogames, Any
93
+ collection :hobbies, Any
94
+ collection :vinyls, Any
95
+ collection :pets, Any
96
+ collection :skills, Any
97
+ collection :dreams, Any
98
+ collection :books, ReeDaoAggTest::Book
99
+ collection :active_books, ReeDaoAggTest::Book
122
100
  end
123
101
 
124
102
  [
125
- :organization,
126
- :passport,
127
- :movies,
128
- :videogames,
129
- :hobbies,
130
- :vinyls,
131
- :pets,
132
- :skills,
133
- :dreams,
134
- :custom_field
103
+
135
104
  ].each do |attr|
136
105
  define_method("set_#{attr}") do |*args|
137
106
  instance_variable_set("@#{attr}", *args)
@@ -141,198 +110,161 @@ class ReeDaoAggTest::User
141
110
  instance_variable_get("@#{attr}")
142
111
  end
143
112
  end
144
-
145
- attr_accessor :name, :age, :organization_id
146
113
  end
147
114
 
148
115
  class ReeDaoAggTest::UserDto
149
- include ReeDto::EntityDSL
150
-
151
- properties(
152
- id: Integer,
153
- organization_id: Integer,
154
- name: String,
155
- full_name: String,
156
- )
157
-
158
- def set_organization(org)
159
- @organization = org; nil
160
- end
116
+ include ReeDto::DSL
161
117
 
162
- def organization
163
- @organization
164
- end
118
+ build_dto do
119
+ field :id, Integer
120
+ field :organization_id, Integer
121
+ field :name, String
122
+ field :full_name, String
165
123
 
166
- def set_books(books)
167
- @books = books; nil
168
- end
124
+ field :organization, Any
169
125
 
170
- def books
171
- @books
126
+ collection :books, ReeDaoAggTest::BookDto
172
127
  end
173
128
  end
174
129
 
175
130
  class ReeDaoAggTest::Organization
176
- include ReeDto::EntityDSL
131
+ include ReeDto::DSL
177
132
 
178
- properties(
179
- id: Nilor[Integer],
180
- name: String
181
- )
133
+ build_dto do
134
+ field :id, Nilor[Integer], default: nil
135
+ field :name, String
182
136
 
183
- contract(Array[ReeDaoAggTest::User] => nil)
184
- def set_users(users)
185
- @users = users; nil
137
+ collection :users, ReeDaoAggTest::User
186
138
  end
187
-
188
- def users
189
- @users ||= []
190
- end
191
-
192
- attr_accessor :name
193
139
  end
194
140
 
195
141
 
196
142
  class ReeDaoAggTest::UserPassport
197
- include ReeDto::EntityDSL
198
-
199
- properties(
200
- id: Nilor[Integer],
201
- user_id: Integer,
202
- info: Nilor[String]
203
- )
143
+ include ReeDto::DSL
204
144
 
205
- attr_accessor :info, :user_id
145
+ build_dto do
146
+ field :id, Nilor[Integer], default: nil
147
+ field :user_id, Integer
148
+ field :info, Nilor[String], default: nil
149
+ end
206
150
  end
207
151
 
208
152
  class ReeDaoAggTest::Movie
209
- include ReeDto::EntityDSL
153
+ include ReeDto::DSL
210
154
 
211
- properties(
212
- id: Nilor[Integer],
213
- user_id: Integer,
214
- title: Nilor[String]
215
- )
155
+ build_dto do
156
+ field :id, Nilor[Integer], default: nil
157
+ field :user_id, Integer
158
+ field :title, Nilor[String], default: nil
159
+ end
216
160
  end
217
161
 
218
162
  class ReeDaoAggTest::Videogame
219
- include ReeDto::EntityDSL
163
+ include ReeDto::DSL
220
164
 
221
- properties(
222
- id: Nilor[Integer],
223
- user_id: Integer,
224
- title: Nilor[String]
225
- )
165
+ build_dto do
166
+ field :id, Nilor[Integer], default: nil
167
+ field :user_id, Integer
168
+ field :title, Nilor[String], default: nil
169
+ end
226
170
  end
227
171
 
228
172
  class ReeDaoAggTest::Hobby
229
- include ReeDto::EntityDSL
173
+ include ReeDto::DSL
230
174
 
231
- properties(
232
- id: Nilor[Integer],
233
- user_id: Integer,
234
- title: Nilor[String]
235
- )
175
+ build_dto do
176
+ field :id, Nilor[Integer], default: nil
177
+ field :user_id, Integer
178
+ field :title, Nilor[String], default: nil
179
+ end
236
180
  end
237
181
 
238
182
  class ReeDaoAggTest::Vinyl
239
- include ReeDto::EntityDSL
183
+ include ReeDto::DSL
240
184
 
241
- properties(
242
- id: Nilor[Integer],
243
- user_id: Integer,
244
- title: Nilor[String]
245
- )
185
+ build_dto do
186
+ field :id, Nilor[Integer], default: nil
187
+ field :user_id, Integer
188
+ field :title, Nilor[String], default: nil
189
+ end
246
190
  end
247
191
 
248
192
  class ReeDaoAggTest::Pet
249
- include ReeDto::EntityDSL
193
+ include ReeDto::DSL
250
194
 
251
- properties(
252
- id: Nilor[Integer],
253
- user_id: Integer,
254
- name: Nilor[String]
255
- )
195
+ build_dto do
196
+ field :id, Nilor[Integer], default: nil
197
+ field :user_id, Integer
198
+ field :name, Nilor[String], default: nil
199
+ end
256
200
  end
257
201
 
258
202
  class ReeDaoAggTest::Skill
259
- include ReeDto::EntityDSL
203
+ include ReeDto::DSL
260
204
 
261
- properties(
262
- id: Nilor[Integer],
263
- user_id: Integer,
264
- title: Nilor[String]
265
- )
205
+ build_dto do
206
+ field :id, Nilor[Integer], default: nil
207
+ field :user_id, Integer
208
+ field :title, Nilor[String], default: nil
209
+ end
266
210
  end
267
211
 
268
212
  class ReeDaoAggTest::Dream
269
- include ReeDto::EntityDSL
213
+ include ReeDto::DSL
270
214
 
271
- properties(
272
- id: Nilor[Integer],
273
- user_id: Integer,
274
- description: Nilor[String]
275
- )
215
+ build_dto do
216
+ field :id, Nilor[Integer], default: nil
217
+ field :user_id, Integer
218
+ field :description, Nilor[String], default: nil
219
+ end
276
220
  end
277
221
 
278
222
  class ReeDaoAggTest::Chapter
279
- include ReeDto::EntityDSL
280
-
281
- properties(
282
- id: Nilor[Integer],
283
- book_id: Integer,
284
- title: Nilor[String]
285
- )
223
+ include ReeDto::DSL
286
224
 
287
- attr_accessor :title, :book_id
225
+ build_dto do
226
+ field :id, Nilor[Integer], default: nil
227
+ field :book_id, Integer
228
+ field :title, Nilor[String], default: nil
229
+ end
288
230
  end
289
231
 
290
232
  class ReeDaoAggTest::ChapterDto < SimpleDelegator
291
233
  end
292
234
 
293
235
  class ReeDaoAggTest::Author
294
- include ReeDto::EntityDSL
295
-
296
- properties(
297
- id: Nilor[Integer],
298
- book_id: Integer,
299
- name: Nilor[String]
300
- )
236
+ include ReeDto::DSL
301
237
 
302
- attr_accessor :name, :book_id
238
+ build_dto do
239
+ field :id, Nilor[Integer], default: nil
240
+ field :book_id, Integer
241
+ field :name, Nilor[String], default: nil
242
+ end
303
243
  end
304
244
 
305
245
  class ReeDaoAggTest::AuthorDto < SimpleDelegator
306
246
  end
307
247
 
308
- class ReeDaoAggTest::Review
309
- include ReeDto::EntityDSL
310
-
311
- properties(
312
- id: Nilor[Integer],
313
- book_id: Integer,
314
- rating: Nilor[Integer]
315
- )
316
-
317
- def set_review_author(review_author)
318
- @review_author = review_author
319
- end
248
+ class ReeDaoAggTest::ReviewAuthor
249
+ include ReeDto::DSL
320
250
 
321
- def review_author
322
- @review_author
251
+ build_dto do
252
+ field :id, Nilor[Integer], default: nil
253
+ field :review_id, Integer
254
+ field :name, String, default: nil
323
255
  end
324
-
325
- attr_accessor :rating, :book_id
326
256
  end
327
257
 
328
- class ReeDaoAggTest::ReviewAuthor
329
- include ReeDto::EntityDSL
258
+ class ReeDaoAggTest::Review
259
+ include ReeDto::DSL
260
+
261
+ build_dto do
262
+ field :id, Nilor[Integer], default: nil
263
+ field :book_id, Integer
264
+ field :rating, Nilor[Integer], default: nil
330
265
 
331
- properties(
332
- id: Nilor[Integer],
333
- review_id: Integer,
334
- name: String
335
- )
266
+ field :review_author, Nilor[ReeDaoAggTest::ReviewAuthor], default: nil
267
+ end
336
268
  end
337
269
 
338
270
  class ReeDaoAggTest::Users
@@ -33,6 +33,15 @@ class ReeDto::DtoCollection
33
33
  @list.inspect
34
34
  end
35
35
 
36
+ contract Any => Bool
37
+ def ==(other)
38
+ if other.is_a?(self.class)
39
+ @list == other.instance_variable_get(:@list)
40
+ else
41
+ @list == other
42
+ end
43
+ end
44
+
36
45
  class << self
37
46
  def filter(name, filter_proc)
38
47
  define_method name do
@@ -90,8 +90,10 @@ module ReeDto::DtoInstanceMethods
90
90
  end
91
91
  end
92
92
 
93
- contract Block => Any
93
+ contract Optblock => Any
94
94
  def each_field(&proc)
95
+ return enum_for(:each_field) unless block_given?
96
+
95
97
  self.class.fields.select { has_value?(_1.name) }.each do |field|
96
98
  proc.call(field.name, get_value(field.name))
97
99
  end
@@ -101,8 +103,8 @@ module ReeDto::DtoInstanceMethods
101
103
  def to_s
102
104
  result = "#<dto #{self.class} "
103
105
 
104
- data = self.class.fields.select { has_value?(_1.name) }.map do |field|
105
- "#{field.name}=#{inspect_value(get_value(field.name))}"
106
+ data = each_field.map do |name, value|
107
+ "#{name}=#{inspect_value(value)}"
106
108
  end
107
109
 
108
110
  data += self.class.collections.select { send(_1.name).size > 0 }.map do |col|
@@ -118,6 +120,15 @@ module ReeDto::DtoInstanceMethods
118
120
  to_s
119
121
  end
120
122
 
123
+ contract Any => Bool
124
+ def ==(other)
125
+ return false unless other.is_a?(self.class)
126
+
127
+ each_field.all? do |name, value|
128
+ other.get_value(name) == value
129
+ end
130
+ end
131
+
121
132
  private
122
133
 
123
134
  def inspect_value(v)
@@ -141,4 +141,38 @@ RSpec.describe ReeDto::DSL do
141
141
  expect(dto.users.active.size).to eq(1)
142
142
  }
143
143
  end
144
+
145
+ describe "#==" do
146
+ it {
147
+ expect(
148
+ ReeDto::DtoClass.new(string: "str")
149
+ ).to eq(
150
+ ReeDto::DtoClass.new(string: "str")
151
+ )
152
+ }
153
+
154
+ it {
155
+ expect(
156
+ ReeDto::DtoClass.new(string: "str")
157
+ ).to eq(
158
+ ReeDto::DtoClass.new(string: "str", without_setter: 0)
159
+ )
160
+ }
161
+
162
+ it {
163
+ expect(
164
+ ReeDto::DtoClass.new(string: "str")
165
+ ).not_to eq(
166
+ ReeDto::DtoClass.new(string: "str2")
167
+ )
168
+ }
169
+
170
+ it {
171
+ expect(
172
+ ReeDto::DtoClass.new(string: "str")
173
+ ).not_to eq(
174
+ ReeDto::DtoClass.new(string: "str", with_default: 2)
175
+ )
176
+ }
177
+ end
144
178
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.119"
4
+ VERSION = "1.0.121"
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.119
4
+ version: 1.0.121
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-14 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree
@@ -321,6 +321,7 @@ files:
321
321
  - lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb
322
322
  - lib/ree_lib/packages/ree_dao/package/ree_dao/beans/connections.rb
323
323
  - lib/ree_lib/packages/ree_dao/package/ree_dao/contract/dao_dataset_contract.rb
324
+ - lib/ree_lib/packages/ree_dao/package/ree_dao/contract/dto_contract.rb
324
325
  - lib/ree_lib/packages/ree_dao/package/ree_dao/contract/entity_contract.rb
325
326
  - lib/ree_lib/packages/ree_dao/package/ree_dao/dataset_extensions.rb
326
327
  - lib/ree_lib/packages/ree_dao/package/ree_dao/dsl.rb