sequel-table_inheritance 0.1.3 → 0.2.0
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 +4 -4
- data/LICENSE.txt +4 -0
- data/lib/sequel/plugins/hybrid_table_inheritance.rb +49 -59
- data/sequel-table_inheritance.gemspec +2 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ed02978f796f7ae6935d6802fc0726e41f217a6
|
4
|
+
data.tar.gz: de34bede536d2c62d471201a3f57a236c2b65c1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ed4d1a0f4653381fd67a51e296d75d33bf22f3b78813d77c50aba3f84a841ca1307d8b629d0822f3622e024523bf8b8c5e9f2182b09f124bef1b43d86c95c9
|
7
|
+
data.tar.gz: 751b1b4a598b7f091ea0bb92071da3d81f0ce46db13b618a8a2f8350c04a609780025805b09c58043cf93cb60ad3b6a8e1276777ce9928d4f6dbcf2ca8003c07
|
data/LICENSE.txt
CHANGED
@@ -2,6 +2,10 @@ The MIT License (MIT)
|
|
2
2
|
|
3
3
|
Copyright (c) 2015 Quinn Harris
|
4
4
|
|
5
|
+
Significant parts copied from Sequel (https://github.com/jeremyevans/sequel):
|
6
|
+
Copyright (c) 2007-2008 Sharon Rosner
|
7
|
+
Copyright (c) 2008-2015 Jeremy Evans
|
8
|
+
|
5
9
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
10
|
of this software and associated documentation files (the "Software"), to deal
|
7
11
|
in the Software without restriction, including without limitation the rights
|
@@ -229,15 +229,6 @@ module Sequel
|
|
229
229
|
# Eager loading option
|
230
230
|
attr_reader :cti_subclass_load
|
231
231
|
|
232
|
-
# Hash with table name symbol keys and arrays of column symbol values,
|
233
|
-
# giving the columns to update in each backing database table.
|
234
|
-
# Only needed to be compatible with class_table_inheritance plugin
|
235
|
-
def cti_columns
|
236
|
-
h = {}
|
237
|
-
cti_models.each { |m| h[m.table_name] = m.cti_table_columns }
|
238
|
-
h
|
239
|
-
end
|
240
|
-
|
241
232
|
# An array of column symbols for the backing database table,
|
242
233
|
# giving the columns to update in each backing database table.
|
243
234
|
attr_reader :cti_table_columns
|
@@ -256,29 +247,35 @@ module Sequel
|
|
256
247
|
# the implicit naming is incorrect.
|
257
248
|
attr_reader :cti_table_map
|
258
249
|
|
250
|
+
# Hash with table name symbol keys and arrays of column symbol values,
|
251
|
+
# giving the columns to update in each backing database table.
|
252
|
+
# Only needed to be compatible with class_table_inheritance plugin
|
253
|
+
def cti_columns
|
254
|
+
h = {}
|
255
|
+
cti_models.each { |m| h[m.table_name] = m.cti_table_columns }
|
256
|
+
h
|
257
|
+
end
|
258
|
+
|
259
|
+
# Alias to single_table_inheritance methods to be compatible with
|
260
|
+
# class_table_inheritance plugin
|
261
|
+
def cti_key; sti_key; end
|
262
|
+
def cti_model_map; sti_model_map; end
|
263
|
+
|
264
|
+
Plugins.inherited_instance_variables(self, :@cti_models=>nil, :@cti_tables=>nil, :@cti_table_columns=>nil, :@cti_instance_dataset=>nil, :@cti_subclass_load=>nil, :@cti_table_map=>nil, :@cti_subclass_datasets=>proc{|v| {} })
|
265
|
+
|
259
266
|
def inherited(subclass)
|
260
267
|
ds = sti_dataset
|
261
268
|
|
262
269
|
# Prevent inherited in model/base.rb from setting the dataset
|
263
270
|
subclass.instance_eval { @dataset = nil }
|
264
271
|
|
265
|
-
|
266
|
-
super # Call single_table_inheritance
|
267
|
-
@cti_tables.pop
|
268
|
-
|
269
|
-
cm = cti_models
|
270
|
-
ctm = cti_table_map
|
271
|
-
ct = cti_tables
|
272
|
-
ctc = cti_table_columns
|
273
|
-
cid = cti_instance_dataset
|
274
|
-
pk = primary_key
|
275
|
-
csl = cti_subclass_load
|
272
|
+
super
|
276
273
|
|
277
274
|
# Set table if this is a class table inheritance
|
278
275
|
table = nil
|
279
276
|
columns = nil
|
280
277
|
if (n = subclass.name) && !n.empty?
|
281
|
-
if table =
|
278
|
+
if table = cti_table_map[n.to_sym]
|
282
279
|
columns = db.from(table).columns
|
283
280
|
else
|
284
281
|
table = subclass.implicit_table_name
|
@@ -288,47 +285,40 @@ module Sequel
|
|
288
285
|
end
|
289
286
|
table = nil if table && (table == table_name)
|
290
287
|
|
291
|
-
|
292
|
-
@cti_table_map = ctm
|
293
|
-
@cti_subclass_load = csl
|
294
|
-
@cti_subclass_datasets = {}
|
288
|
+
return unless table
|
295
289
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
sd =
|
314
|
-
unless d = sd[cm.last]
|
315
|
-
sd[self] = db.from(table).select(*columns.map{|cc| Sequel.qualify(table_name, Sequel.identifier(cc))})
|
316
|
-
else
|
317
|
-
sd[self] = d.join(table, pk=>pk).select_append(*sel_app)
|
318
|
-
end
|
290
|
+
pk = primary_key
|
291
|
+
subclass.instance_eval do
|
292
|
+
if cti_tables.length == 1
|
293
|
+
ds = ds.select(*self.columns.map{|cc| Sequel.qualify(table_name, Sequel.identifier(cc))})
|
294
|
+
end
|
295
|
+
sel_app = (columns - [pk]).map{|cc| Sequel.qualify(table, Sequel.identifier(cc))}
|
296
|
+
@sti_dataset = ds.join(table, pk=>pk).select_append(*sel_app)
|
297
|
+
set_dataset(@sti_dataset)
|
298
|
+
set_columns(self.columns)
|
299
|
+
dataset.row_proc = lambda{|r| subclass.sti_load(r)}
|
300
|
+
|
301
|
+
unless cti_subclass_load == :lazy_only
|
302
|
+
cti_models.each do |model|
|
303
|
+
sd = model.instance_variable_get(:@cti_subclass_datasets)
|
304
|
+
unless d = sd[cti_table_model]
|
305
|
+
sd[self] = db.from(table).select(*columns.map{|cc| Sequel.qualify(table, Sequel.identifier(cc))})
|
306
|
+
else
|
307
|
+
sd[self] = d.join(table, pk=>pk).select_append(*sel_app)
|
319
308
|
end
|
320
309
|
end
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
310
|
+
end
|
311
|
+
unless cti_subclass_load == :eager_only
|
312
|
+
(columns - [pk]).each{|a| define_lazy_attribute_getter(a, :dataset=>dataset, :table=>table)}
|
313
|
+
end
|
314
|
+
|
315
|
+
@cti_models += [self]
|
316
|
+
@cti_tables += [table]
|
317
|
+
@cti_table_columns = columns
|
318
|
+
@cti_instance_dataset = db.from(table)
|
319
|
+
|
320
|
+
cti_tables.reverse.each do |ct|
|
321
|
+
db.schema(ct).each{|sk,v| db_schema[sk] = v}
|
332
322
|
end
|
333
323
|
end
|
334
324
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
#require 'sequel/table_inheritance/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
6
|
s.name = "sequel-table_inheritance"
|
8
|
-
s.version = '0.
|
7
|
+
s.version = '0.2.0'
|
9
8
|
s.authors = ["Quinn Harris"]
|
10
9
|
s.email = ["sequel@quinnharris.me"]
|
11
10
|
|
@@ -23,5 +22,5 @@ Gem::Specification.new do |s|
|
|
23
22
|
s.add_development_dependency "rake", "~> 10.0"
|
24
23
|
s.add_development_dependency "rspec"
|
25
24
|
|
26
|
-
s.add_dependency "sequel", "~> 4.
|
25
|
+
s.add_dependency "sequel", "~> 4.22"
|
27
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-table_inheritance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Quinn Harris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '4.
|
61
|
+
version: '4.22'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '4.
|
68
|
+
version: '4.22'
|
69
69
|
description: Alternative to single and class table inheritance plugins for sequel
|
70
70
|
email:
|
71
71
|
- sequel@quinnharris.me
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.2.3
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Alternative to single and class table inheritance plugins for sequel
|