ree_lib 1.0.61 → 1.0.63

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: a16fe3f260e9c08dfa590a34ffeafce9413115416aaedc37bcb4ee50fbd5ae67
4
- data.tar.gz: d93566783538e0ea2eb9aba94938a3eccdb34901197d5e38afa9f03da9e5f826
3
+ metadata.gz: bf0b2d37f1b4dab2dd798faa601db7969c49479c02eb39ee67a1a7344231b887
4
+ data.tar.gz: aabcce88a49279d7d1d970e59056a43b866edd4d81d0a64cb553c0142b9da4c2
5
5
  SHA512:
6
- metadata.gz: d1b98f584c71eb035a29a411161a9556aef71ce4b2d9e292e219e767e335ba9cbfa3c8b7fa49e776d846732f84af7c7f6cc5ce91bcfe5a975bd7cf91a843ad83
7
- data.tar.gz: b4106abe1f03951c28959f8b9edc4c5f66ff05dcc1788bd2c1e268dd02f0487350ba5074c62eafd73244435dd42a3e034d87e873aaf5c5e11f3791b4884a83f4
6
+ metadata.gz: f9bd4b78d0c104dccaee61ac1ab1979596c2d90c9006c0e939cb26c8984401d7e724edfff81f4ff106b9a5d153ab1a687bf3d1bb963ecefa1929839e81a0183c
7
+ data.tar.gz: cbe3d31611bf98d43bd5cced27d68689bf739e04a87c023e96ede58b9ea500319ec907e2df6ce55f17ff752bc34c4c0e727ab34ed721b51130e251657d6764b3
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.63)
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,26 +271,37 @@ 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
+ if value.is_a?(Array)
277
+ value.map { to_dto.call(_1) }
278
+ else
279
+ to_dto.call(value)
280
+ end
281
+ end
282
+
283
+ self.instance_exec(item, assoc_index, &assoc_setter)
284
+ else
285
+ self.instance_exec(item, association_index, &assoc_setter)
286
+ end
274
287
  else
275
288
  key = if reverse.nil?
276
289
  primary_key
277
290
  else
278
291
  reverse ? primary_key : "#{assoc_name}_id"
279
292
  end
293
+
280
294
  value = association_index[item.send(key)]
281
295
 
282
296
  if to_dto && !value.nil?
283
- if value.is_a?(Array)
284
- value = value.map { to_dto.call(_1) }
297
+ value = if value.is_a?(Array)
298
+ value.map { to_dto.call(_1) }
285
299
  else
286
- value = to_dto.call(value)
300
+ to_dto.call(value)
287
301
  end
288
302
  end
289
303
 
290
- if value.nil? && multiple
291
- value = []
292
- end
304
+ value = [] if value.nil? && multiple
293
305
 
294
306
  begin
295
307
  item.send(assoc_setter, value)
@@ -43,7 +43,7 @@ module ReeDao
43
43
  def belongs_to(assoc_name, opts = nil, &block)
44
44
  association(__method__, assoc_name, opts, &block)
45
45
  end
46
-
46
+
47
47
  contract(
48
48
  Symbol,
49
49
  Nilor[Proc, Sequel::Dataset],
@@ -52,7 +52,7 @@ module ReeDao
52
52
  def has_one(assoc_name, opts = nil, &block)
53
53
  association(__method__, assoc_name, opts, &block)
54
54
  end
55
-
55
+
56
56
  contract(
57
57
  Symbol,
58
58
  Nilor[Proc, Sequel::Dataset],
@@ -61,7 +61,7 @@ module ReeDao
61
61
  def has_many(assoc_name, opts = nil, &block)
62
62
  association(__method__, assoc_name, opts, &block)
63
63
  end
64
-
64
+
65
65
  contract(Symbol, Proc => Any)
66
66
  def field(assoc_name, proc)
67
67
  association(__method__, assoc_name, proc)
@@ -83,8 +83,9 @@ module ReeDao
83
83
  def association(assoc_type, assoc_name, opts, &block)
84
84
  if self.class.sync_mode?
85
85
  return if association_is_not_included?(assoc_name) || list.empty?
86
-
86
+
87
87
  association = Association.new(self, parent_dao_name, list, **global_opts)
88
+
88
89
  if assoc_type == :field
89
90
  association.handle_field(assoc_name, opts)
90
91
  else
@@ -92,14 +93,14 @@ module ReeDao
92
93
  end
93
94
  else
94
95
  if association_is_not_included?(assoc_name) || list.empty?
95
- return { association_threads: @assoc_threads, field_threads: @field_threads }
96
+ return { association_threads: @assoc_threads, field_threads: @field_threads }
96
97
  end
97
98
 
98
99
  association = Association.new(self, parent_dao_name, list, **global_opts)
99
100
 
100
101
  if assoc_type == :field
101
102
  field_proc = opts
102
- {
103
+ {
103
104
  association_threads: @assoc_threads,
104
105
  field_threads: @field_threads << [
105
106
  association, field_proc
@@ -125,7 +126,7 @@ module ReeDao
125
126
 
126
127
  if only && !only.include?(assoc_name)
127
128
  return false if autoload_children
128
- return true
129
+ return true
129
130
  end
130
131
  end
131
132
 
@@ -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.63"
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.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov