ree_lib 1.0.61 → 1.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a16fe3f260e9c08dfa590a34ffeafce9413115416aaedc37bcb4ee50fbd5ae67
4
- data.tar.gz: d93566783538e0ea2eb9aba94938a3eccdb34901197d5e38afa9f03da9e5f826
3
+ metadata.gz: e69b23ef012a6748604d4b82d1d81c791902ee23bc6179d231a340e48289a5d7
4
+ data.tar.gz: 6233c958a32bfdeea0efaf5b5692d0e824a5e04d9d334bf002d519b0789d6cc3
5
5
  SHA512:
6
- metadata.gz: d1b98f584c71eb035a29a411161a9556aef71ce4b2d9e292e219e767e335ba9cbfa3c8b7fa49e776d846732f84af7c7f6cc5ce91bcfe5a975bd7cf91a843ad83
7
- data.tar.gz: b4106abe1f03951c28959f8b9edc4c5f66ff05dcc1788bd2c1e268dd02f0487350ba5074c62eafd73244435dd42a3e034d87e873aaf5c5e11f3791b4884a83f4
6
+ metadata.gz: eee96a99fe5217675f4ff9c3db4915571ae444c7af4a33ca763b786b51a07f77f55fe794aa004688ccfd0f6c00f478631ba100181625de5d5f8d503f62b85edb
7
+ data.tar.gz: 1abc64ad140c4901e52f62b9a74f30e16f9fd4364a5e066f5321597c4246b7c5d7e2a0cba0515396b1a18aacd27d786321b17fa29004ed7336fac22a8ee75b06
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.61)
4
+ ree_lib (1.0.62)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -4,6 +4,7 @@ module ReeDao
4
4
 
5
5
  link :group_by, from: :ree_array
6
6
  link :index_by, from: :ree_array
7
+ link :transform_values, from: :ree_hash
7
8
 
8
9
  attr_reader :parent, :parent_dao_name, :list, :global_opts
9
10
 
@@ -141,7 +142,7 @@ module ReeDao
141
142
  contract(
142
143
  Symbol,
143
144
  Symbol,
144
- Array,
145
+ Array,
145
146
  Kwargs[
146
147
  primary_key: Nilor[Symbol],
147
148
  foreign_key: Nilor[Symbol],
@@ -160,12 +161,12 @@ module ReeDao
160
161
  items = scope
161
162
  else
162
163
  assoc_dao = find_dao(assoc_name, parent, scope)
163
-
164
+
164
165
  if reverse
165
166
  if !foreign_key
166
- foreign_key = "#{parent_assoc_name.to_s.gsub(/e?s$/,'')}_id".to_sym
167
+ foreign_key = "#{parent_assoc_name.to_s.gsub(/s$/,'')}_id".to_sym
167
168
  end
168
-
169
+
169
170
  root_ids = list.map(&:id).uniq
170
171
  else
171
172
  if !foreign_key
@@ -174,10 +175,10 @@ module ReeDao
174
175
 
175
176
  root_ids = list.map(&:"#{foreign_key}").compact
176
177
  end
177
-
178
+
178
179
  scope ||= assoc_dao
179
180
  scope = scope.where((reverse ? foreign_key : :id) => root_ids)
180
-
181
+
181
182
  items = add_scopes(scope, global_opts[assoc_name])
182
183
  end
183
184
 
@@ -219,14 +220,14 @@ module ReeDao
219
220
  else
220
221
  assoc_dao = nil
221
222
  assoc_dao = find_dao(assoc_name, parent, scope)
222
-
223
- foreign_key ||= "#{parent_assoc_name.to_s.gsub(/e?s$/,'')}_id".to_sym
224
-
223
+
224
+ foreign_key ||= "#{parent_assoc_name.to_s.gsub(/s$/, '')}_id".to_sym
225
+
225
226
  root_ids = list.map(&:"#{primary_key}")
226
-
227
+
227
228
  scope ||= assoc_dao
228
229
  scope = scope.where(foreign_key => root_ids)
229
-
230
+
230
231
  items = add_scopes(scope, global_opts[assoc_name])
231
232
  end
232
233
 
@@ -270,13 +271,22 @@ module ReeDao
270
271
 
271
272
  list.each do |item|
272
273
  if setter && setter.is_a?(Proc)
273
- self.instance_exec(item, association_index, &assoc_setter)
274
+ if to_dto
275
+ assoc_index = transform_values(association_index) do |key, value|
276
+ to_dto.call(value)
277
+ end
278
+
279
+ self.instance_exec(item, assoc_index, &assoc_setter)
280
+ else
281
+ self.instance_exec(item, association_index, &assoc_setter)
282
+ end
274
283
  else
275
284
  key = if reverse.nil?
276
285
  primary_key
277
286
  else
278
287
  reverse ? primary_key : "#{assoc_name}_id"
279
288
  end
289
+
280
290
  value = association_index[item.send(key)]
281
291
 
282
292
  if to_dto && !value.nil?
@@ -129,7 +129,7 @@ RSpec.describe :load_agg do
129
129
  end
130
130
 
131
131
  def call(ids_or_scope)
132
- load_agg(ids_or_scope, users) do
132
+ load_agg(users, ids_or_scope) do
133
133
  belongs_to :organization
134
134
 
135
135
  has_many :books
@@ -141,7 +141,7 @@ RSpec.describe :load_agg do
141
141
  has_many :skills
142
142
  has_many :dreams
143
143
 
144
- has_one :passport, foreign_key: :user_id, scope: user_passports
144
+ has_one :passport, -> { {foreign_key: :user_id, scope: user_passports} }
145
145
  end
146
146
  end
147
147
  end
@@ -251,7 +251,7 @@ RSpec.describe :load_agg do
251
251
 
252
252
  _users = []
253
253
  st_time = Time.now
254
- puts "Starting to seed #{NUM_OF_USERS} users..."
254
+ puts "Seeding #{NUM_OF_USERS} users..."
255
255
  NUM_OF_USERS.times do
256
256
  u = ReeDaoLoadAggTest::User.new(
257
257
  name: Faker::Name.name,
@@ -104,7 +104,7 @@ RSpec.describe :load_agg do
104
104
  has_many :books do |books_list|
105
105
  has_one :author
106
106
  has_many :chapters
107
-
107
+
108
108
  has_many :reviews do |reviews_list|
109
109
  has_one :review_author
110
110
 
@@ -113,7 +113,7 @@ RSpec.describe :load_agg do
113
113
 
114
114
  field :book_calculatetable_field, -> { change_book_titles(books_list) }
115
115
  end
116
-
116
+
117
117
  has_one :passport, -> { passport_opts }
118
118
  has_one :custom_field, -> { custom_field_opts }
119
119
 
@@ -166,7 +166,7 @@ RSpec.describe :load_agg do
166
166
 
167
167
  has_many :books, -> { books_opts } do
168
168
  has_one :author, -> { author_opts }
169
- has_many :chapters, -> { chapters_opts }
169
+ has_many :chapters, -> { chapters_opts }
170
170
  end
171
171
  end
172
172
  end
@@ -174,7 +174,12 @@ RSpec.describe :load_agg do
174
174
  private
175
175
 
176
176
  def books_opts
177
- { to_dto: -> (book) { ReeDaoLoadAggTest::BookDto.new(book) }}
177
+ {
178
+ to_dto: -> (book) { ReeDaoLoadAggTest::BookDto.new(book) },
179
+ setter: -> (item, child_index) {
180
+ item.set_books(child_index[item.id] || [])
181
+ }
182
+ }
178
183
  end
179
184
 
180
185
  def author_opts
@@ -205,7 +210,7 @@ RSpec.describe :load_agg do
205
210
  has_many :books, -> { books_opts } do
206
211
  has_one :author
207
212
  has_many :chapters
208
-
213
+
209
214
  has_many :reviews do
210
215
  has_one :review_author
211
216
  end
@@ -214,7 +219,7 @@ RSpec.describe :load_agg do
214
219
  end
215
220
 
216
221
  private
217
-
222
+
218
223
  def books_opts
219
224
  { autoload_children: true }
220
225
  end
@@ -239,7 +244,7 @@ RSpec.describe :load_agg do
239
244
  has_many :books do
240
245
  has_one :author
241
246
  has_many :chapters
242
-
247
+
243
248
  has_many :reviews, -> { { autoload_children: true } } do
244
249
  has_one :review_author
245
250
  end
@@ -435,7 +440,7 @@ RSpec.describe :load_agg do
435
440
  books.put(book_1)
436
441
  books.put(book_2)
437
442
  books.put(book_3)
438
-
443
+
439
444
  res = users_agg_only_dataset.call(users.where(name: "John"))
440
445
 
441
446
  user = res[0]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.61"
4
+ VERSION = "1.0.62"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.61
4
+ version: 1.0.62
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov