ree_lib 1.0.120 → 1.0.122

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: e2116bbd5ccddea0d1712d9735936d9254e39218adda88a3b5589e8f38b10683
4
- data.tar.gz: 878f695cf24c9f46bf41549a5213bf03e63d58f2a957c255a4b12559926dd86c
3
+ metadata.gz: '03921ccbd7050911caf9c2ff781b825b5b0c68e3ac461c0ca03b5a857aa32be9'
4
+ data.tar.gz: fe55c4f54db004e5603a198293b23feaef1538541b034137943d0dd990ebec39
5
5
  SHA512:
6
- metadata.gz: 69ea27c870a0e5982eb019afa07486f00c6e21e5c916505141cb31748971bd2dab19f05ebecb5c58011540e6eb5e120971c28fe8a9fe9833df512ce459ac15d9
7
- data.tar.gz: b0a5671bf0744fb788a825bc09a6b512b85c3db28f1717bbd91f79184e4372cd4f2bab963588ecd1b7c40b41caa5857fe529e1035aab1e23706e87f3fef3eadd
6
+ metadata.gz: 3b40ee304d8c9b72f81b80ce0e63687bad7f301ee4fd3f16bfa5628a61a3e5f47d796b1e5a197b93bc6c48fdfb90973a8512db1b283d4403770f4cfdcecb67ac
7
+ data.tar.gz: 15de0a6eacc51bf19cb406ddfd9b0f016ab2720ed4d6a3c6d4b7da835961590b9ba6417a1931518227508b46a6a80e7a68f6de88e126d31f997be02e788492ad
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.120)
4
+ ree_lib (1.0.122)
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)
@@ -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
@@ -56,6 +56,11 @@ module ReeDto::DtoInstanceMethods
56
56
  @_attrs
57
57
  end
58
58
 
59
+ contract None => Hash
60
+ def to_h
61
+ each_field.to_h
62
+ end
63
+
59
64
  contract Symbol, Any => Any
60
65
  def set_attr(name, val)
61
66
  @_attrs[name] = val
@@ -90,8 +95,10 @@ module ReeDto::DtoInstanceMethods
90
95
  end
91
96
  end
92
97
 
93
- contract Block => Any
98
+ contract Optblock => Any
94
99
  def each_field(&proc)
100
+ return enum_for(:each_field) unless block_given?
101
+
95
102
  self.class.fields.select { has_value?(_1.name) }.each do |field|
96
103
  proc.call(field.name, get_value(field.name))
97
104
  end
@@ -101,8 +108,8 @@ module ReeDto::DtoInstanceMethods
101
108
  def to_s
102
109
  result = "#<dto #{self.class} "
103
110
 
104
- data = self.class.fields.select { has_value?(_1.name) }.map do |field|
105
- "#{field.name}=#{inspect_value(get_value(field.name))}"
111
+ data = each_field.map do |name, value|
112
+ "#{name}=#{inspect_value(value)}"
106
113
  end
107
114
 
108
115
  data += self.class.collections.select { send(_1.name).size > 0 }.map do |col|
@@ -118,6 +125,15 @@ module ReeDto::DtoInstanceMethods
118
125
  to_s
119
126
  end
120
127
 
128
+ contract Any => Bool
129
+ def ==(other)
130
+ return false unless other.is_a?(self.class)
131
+
132
+ each_field.all? do |name, value|
133
+ other.get_value(name) == value
134
+ end
135
+ end
136
+
121
137
  private
122
138
 
123
139
  def inspect_value(v)
@@ -141,4 +141,45 @@ 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
178
+
179
+ describe "#to_h" do
180
+ it {
181
+ dto = ReeDto::DtoClass.new(string: "str")
182
+ expect(dto.to_h).to eq({ string: "str", with_default: 1 })
183
+ }
184
+ end
144
185
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.120"
4
+ VERSION = "1.0.122"
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.120
4
+ version: 1.0.122
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