ree_lib 1.0.71 → 1.0.72

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: 83750e368c52ed97daa01d069e57a184129c6bafb7bd7867aa8c71685562da16
4
- data.tar.gz: 37ea4a0f4c852bed89692d47f5c86891f281a16f1e13f04faeb2670f57bfd173
3
+ metadata.gz: 0421ad28472f902b4c53091515c749bdcb6aba9ef96ed42009abe27d115edf48
4
+ data.tar.gz: 3909bfecb3e92e05708a9be5effb672fc8042e2f53ed4aadb426539f0eba8574
5
5
  SHA512:
6
- metadata.gz: ff00e69c9a2b54dd03eee000076e3aac5cb0236b53cdbba0ed669eba2d5918d1c14d88f0c8a6d8e58497a86e02208a0f5850fbef294e552ad2f994aaa83cf89c
7
- data.tar.gz: bb9a5580e423c17d894d07a69896f39d0d26ef9fc21b8bd3871c505034516a20fa2c5bf6a95827a1733a4cb06a6e6fea7bb4dd0a0e4735f13eca1fb5f2087cb9
6
+ metadata.gz: bb696f99d8af84de496f0e6a3bf616256853302d952409832fd89eb24830c0f29cb2cead19b245eee883a2c9dc7d358633bccc308be56369c2d8aeb569a66c7d
7
+ data.tar.gz: 0accc79d4259f341f4fbf6306103e28521b070119b2ee6be3e7bb98e08802b78ad857f476524a128d9c51cd7ca02fb59298ac70886b70a1304de8d39455d13d5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.71)
4
+ ree_lib (1.0.72)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -3,14 +3,12 @@ module ReeDao
3
3
  include Ree::LinkDSL
4
4
  include ReeDao::AssociationMethods
5
5
 
6
- link :demodulize, from: :ree_string
7
6
  link :group_by, from: :ree_array
8
7
  link :index_by, from: :ree_array
9
- link :underscore, from: :ree_string
10
8
 
11
9
  attr_reader :parent, :parent_dao, :list, :global_opts
12
10
 
13
- contract(ReeDao::Associations, Sequel::Dataset, Array, Ksplat[RestKeys => Any] => Any)
11
+ contract(ReeDao::Associations, Nilor[Sequel::Dataset], Array, Ksplat[RestKeys => Any] => Any)
14
12
  def initialize(parent, parent_dao, list, **global_opts)
15
13
  @parent = parent
16
14
  @parent_dao = parent_dao
@@ -51,8 +49,7 @@ module ReeDao
51
49
 
52
50
  dao = if scope.is_a?(Array)
53
51
  return [] if scope.empty?
54
- name = underscore(demodulize(scope.first.class.name))
55
- find_dao(name, parent, nil)
52
+ nil
56
53
  else
57
54
  find_dao(assoc_name, parent, scope)
58
55
  end
@@ -125,7 +122,7 @@ module ReeDao
125
122
  **global_opts
126
123
  )
127
124
 
128
- if parent_dao.db.in_transaction? || ReeDao::Associations.sync_mode?
125
+ if parent_dao.nil? || parent_dao.db.in_transaction? || ReeDao::Associations.sync_mode?
129
126
  associations.instance_exec(assoc_list, &block)
130
127
  else
131
128
  threads = associations.instance_exec(assoc_list, &block)
@@ -145,7 +142,7 @@ module ReeDao
145
142
  end
146
143
 
147
144
  contract(
148
- Sequel::Dataset,
145
+ Nilor[Sequel::Dataset],
149
146
  Symbol,
150
147
  Array,
151
148
  Kwargs[
@@ -170,7 +167,11 @@ module ReeDao
170
167
  if reverse
171
168
  # has_one
172
169
  if !foreign_key
173
- foreign_key = "#{parent_dao.first_source_table.to_s.gsub(/s$/,'')}_id".to_sym
170
+ if parent_dao.nil?
171
+ raise ArgumentError.new("foreign_key should be provided for :#{assoc_name} association")
172
+ end
173
+
174
+ foreign_key = foreign_key_from_dao(parent_dao)
174
175
  end
175
176
 
176
177
  root_ids = list.map(&:id).uniq
@@ -206,7 +207,7 @@ module ReeDao
206
207
  end
207
208
 
208
209
  contract(
209
- Sequel::Dataset,
210
+ Nilor[Sequel::Dataset],
210
211
  Symbol,
211
212
  Array,
212
213
  Kwargs[
@@ -228,7 +229,13 @@ module ReeDao
228
229
  assoc_dao = nil
229
230
  assoc_dao = find_dao(assoc_name, parent, scope)
230
231
 
231
- foreign_key ||= "#{parent_dao.first_source_table.to_s.gsub(/s$/, '')}_id".to_sym
232
+ if !foreign_key
233
+ if parent_dao.nil?
234
+ raise ArgumentError.new("foreign_key should be provided for :#{assoc_name} association")
235
+ end
236
+
237
+ foreign_key = foreign_key_from_dao(parent_dao)
238
+ end
232
239
 
233
240
  root_ids = list.map(&:"#{primary_key}")
234
241
 
@@ -343,5 +350,11 @@ module ReeDao
343
350
 
344
351
  parent.agg_caller.send(method, *args, &block)
345
352
  end
353
+
354
+ private
355
+
356
+ def foreign_key_from_dao(dao)
357
+ "#{dao.first_source_table.to_s.gsub(/s$/, '')}_id".to_sym
358
+ end
346
359
  end
347
360
  end
@@ -87,7 +87,7 @@ module ReeDao
87
87
  Optblock => Any
88
88
  )
89
89
  def association(assoc_type, assoc_name, __opts, &block)
90
- if parent_dao.db.in_transaction? || self.class.sync_mode?
90
+ if parent_dao.nil? || parent_dao.db.in_transaction? || self.class.sync_mode?
91
91
  return if association_is_not_included?(assoc_name) || list.empty?
92
92
 
93
93
  association = Association.new(self, parent_dao, list, **global_opts)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.71"
4
+ VERSION = "1.0.72"
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.71
4
+ version: 1.0.72
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov