sequel 1.5.1 → 2.0.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.
- data/CHANGELOG +30 -0
- data/README +12 -15
- data/Rakefile +9 -20
- data/lib/sequel_model.rb +47 -72
- data/lib/sequel_model/association_reflection.rb +59 -0
- data/lib/sequel_model/associations.rb +99 -94
- data/lib/sequel_model/base.rb +308 -102
- data/lib/sequel_model/caching.rb +72 -27
- data/lib/sequel_model/eager_loading.rb +308 -300
- data/lib/sequel_model/hooks.rb +51 -49
- data/lib/sequel_model/inflector.rb +186 -182
- data/lib/sequel_model/plugins.rb +54 -40
- data/lib/sequel_model/record.rb +185 -220
- data/lib/sequel_model/schema.rb +27 -34
- data/lib/sequel_model/validations.rb +54 -73
- data/spec/association_reflection_spec.rb +85 -0
- data/spec/associations_spec.rb +160 -73
- data/spec/base_spec.rb +3 -3
- data/spec/eager_loading_spec.rb +132 -35
- data/spec/hooks_spec.rb +120 -20
- data/spec/inflector_spec.rb +2 -2
- data/spec/model_spec.rb +110 -78
- data/spec/plugins_spec.rb +4 -0
- data/spec/rcov.opts +1 -1
- data/spec/record_spec.rb +160 -59
- data/spec/spec.opts +0 -5
- data/spec/spec_helper.rb +12 -0
- data/spec/validations_spec.rb +23 -0
- metadata +60 -50
- data/lib/sequel_model/deprecated.rb +0 -81
- data/lib/sequel_model/inflections.rb +0 -112
- data/spec/deprecated_relations_spec.rb +0 -113
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -22,12 +22,14 @@ class MockDataset < Sequel::Dataset
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def fetch_rows(sql)
|
25
|
+
return if sql =~ /information_schema/
|
25
26
|
@db.execute(sql)
|
26
27
|
yield({:id => 1, :x => 1})
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
31
|
class MockDatabase < Sequel::Database
|
32
|
+
@@quote_identifiers = false
|
31
33
|
attr_reader :sqls
|
32
34
|
|
33
35
|
def execute(sql)
|
@@ -52,7 +54,17 @@ class << Sequel::Model
|
|
52
54
|
@dataset.instance_variable_set(:@columns, cols) if @dataset
|
53
55
|
define_method(:str_columns){cols.map{|x|x.to_s.freeze}}
|
54
56
|
def_column_accessor(*cols)
|
57
|
+
@columns = cols
|
58
|
+
@db_schema = {}
|
59
|
+
cols.each{|c| @db_schema[c] = {}}
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
63
|
Sequel::Model.db = MODEL_DB = MockDatabase.new
|
64
|
+
|
65
|
+
class Spec::Example::ExampleGroup
|
66
|
+
def self.pt_specify(*args, &block)
|
67
|
+
specify(*args, &block) if defined?(ParseTree)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/spec/validations_spec.rb
CHANGED
@@ -56,6 +56,7 @@ describe Validation do
|
|
56
56
|
setup do
|
57
57
|
@c = Class.new do
|
58
58
|
include Validation
|
59
|
+
attr_reader :before_validation, :after_validation
|
59
60
|
|
60
61
|
def self.validates_coolness_of(attr)
|
61
62
|
validates_each(attr) {|o, a, v| o.errors[a] << 'is not cool' if v != :cool}
|
@@ -64,6 +65,7 @@ describe Validation do
|
|
64
65
|
|
65
66
|
@d = Class.new do
|
66
67
|
attr_accessor :errors
|
68
|
+
attr_reader :before_validation, :after_validation
|
67
69
|
def initialize; @errors = Validation::Errors.new; end
|
68
70
|
end
|
69
71
|
end
|
@@ -111,6 +113,7 @@ describe "A Validation instance" do
|
|
111
113
|
setup do
|
112
114
|
@c = Class.new do
|
113
115
|
attr_accessor :score
|
116
|
+
attr_reader :before_validation, :after_validation
|
114
117
|
|
115
118
|
include Validation
|
116
119
|
|
@@ -147,6 +150,7 @@ describe Validation::Generator do
|
|
147
150
|
|
148
151
|
@c = Class.new do
|
149
152
|
include Validation
|
153
|
+
attr_reader :before_validation, :after_validation
|
150
154
|
|
151
155
|
def self.validates_blah
|
152
156
|
$testit = 1324
|
@@ -166,6 +170,7 @@ describe "Validations" do
|
|
166
170
|
setup do
|
167
171
|
@c = Class.new do
|
168
172
|
attr_accessor :value
|
173
|
+
attr_reader :before_validation, :after_validation
|
169
174
|
include Validation
|
170
175
|
end
|
171
176
|
@m = @c.new
|
@@ -268,6 +273,22 @@ describe "Validations" do
|
|
268
273
|
@m.should be_valid
|
269
274
|
@m.value = '123.1231'
|
270
275
|
@m.should be_valid
|
276
|
+
@m.value = '+1'
|
277
|
+
@m.should be_valid
|
278
|
+
@m.value = '-1'
|
279
|
+
@m.should be_valid
|
280
|
+
@m.value = '+1.123'
|
281
|
+
@m.should be_valid
|
282
|
+
@m.value = '-0.123'
|
283
|
+
@m.should be_valid
|
284
|
+
@m.value = '-0.123E10'
|
285
|
+
@m.should be_valid
|
286
|
+
@m.value = '32.123e10'
|
287
|
+
@m.should be_valid
|
288
|
+
@m.value = '+32.123E10'
|
289
|
+
@m.should be_valid
|
290
|
+
@m.should be_valid
|
291
|
+
@m.value = '.0123'
|
271
292
|
end
|
272
293
|
|
273
294
|
specify "should validate numericality_of with only_integer" do
|
@@ -294,6 +315,7 @@ context "Superclass validations" do
|
|
294
315
|
setup do
|
295
316
|
@c1 = Class.new do
|
296
317
|
include Validation
|
318
|
+
attr_reader :before_validation, :after_validation
|
297
319
|
attr_accessor :value
|
298
320
|
validates_length_of :value, :minimum => 5
|
299
321
|
end
|
@@ -344,6 +366,7 @@ context ".validates with block" do
|
|
344
366
|
specify "should support calling .each" do
|
345
367
|
@c = Class.new do
|
346
368
|
attr_accessor :vvv
|
369
|
+
attr_reader :before_validation, :after_validation
|
347
370
|
|
348
371
|
include Validation
|
349
372
|
validates do
|
metadata
CHANGED
@@ -1,33 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: sequel
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version:
|
7
|
-
date: 2008-04-30 00:00:00 -07:00
|
8
|
-
summary: "The Database Toolkit for Ruby: Model Classes"
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: code@jeremyevans.net
|
12
|
-
homepage: http://sequel.rubyforge.org
|
13
|
-
rubyforge_project: sequel
|
14
|
-
description: "The Database Toolkit for Ruby: Model Classes"
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.4
|
24
|
-
version:
|
4
|
+
version: 2.0.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Jeremy Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-01 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sequel_core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - "="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
23
|
+
version:
|
24
|
+
description: "The Database Toolkit for Ruby: Model Classes"
|
25
|
+
email: code@jeremyevans.net
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- CHANGELOG
|
33
|
+
- COPYING
|
31
34
|
files:
|
32
35
|
- COPYING
|
33
36
|
- README
|
@@ -35,18 +38,18 @@ files:
|
|
35
38
|
- spec/associations_spec.rb
|
36
39
|
- spec/base_spec.rb
|
37
40
|
- spec/caching_spec.rb
|
38
|
-
- spec/
|
41
|
+
- spec/model_spec.rb
|
39
42
|
- spec/eager_loading_spec.rb
|
40
43
|
- spec/hooks_spec.rb
|
41
|
-
- spec/
|
44
|
+
- spec/record_spec.rb
|
42
45
|
- spec/plugins_spec.rb
|
43
46
|
- spec/rcov.opts
|
44
|
-
- spec/record_spec.rb
|
45
|
-
- spec/schema_spec.rb
|
46
47
|
- spec/spec.opts
|
48
|
+
- spec/schema_spec.rb
|
47
49
|
- spec/spec_helper.rb
|
48
50
|
- spec/validations_spec.rb
|
49
51
|
- spec/inflector_spec.rb
|
52
|
+
- spec/association_reflection_spec.rb
|
50
53
|
- lib/sequel.rb
|
51
54
|
- lib/sequel_model.rb
|
52
55
|
- lib/sequel_model
|
@@ -59,35 +62,42 @@ files:
|
|
59
62
|
- lib/sequel_model/record.rb
|
60
63
|
- lib/sequel_model/schema.rb
|
61
64
|
- lib/sequel_model/validations.rb
|
62
|
-
- lib/sequel_model/deprecated.rb
|
63
|
-
- lib/sequel_model/inflections.rb
|
64
65
|
- lib/sequel_model/inflector.rb
|
66
|
+
- lib/sequel_model/association_reflection.rb
|
65
67
|
- CHANGELOG
|
66
|
-
|
67
|
-
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://sequel.rubyforge.org
|
70
|
+
post_install_message:
|
68
71
|
rdoc_options:
|
69
72
|
- --quiet
|
70
73
|
- --line-numbers
|
71
74
|
- --inline-source
|
75
|
+
- --title
|
76
|
+
- "Sequel: The Database Toolkit for Ruby: Model Classes"
|
77
|
+
- --main
|
78
|
+
- README
|
72
79
|
- --exclude
|
73
80
|
- ^(examples|extras)/
|
74
|
-
|
75
|
-
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.8.4
|
88
|
+
version:
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
82
95
|
requirements: []
|
83
96
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 1.5.1
|
93
|
-
version:
|
97
|
+
rubyforge_project: sequel
|
98
|
+
rubygems_version: 1.0.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 2
|
101
|
+
summary: "The Database Toolkit for Ruby: Model Classes"
|
102
|
+
test_files: []
|
103
|
+
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Sequel
|
2
|
-
class Model
|
3
|
-
include Sequel::Deprecation
|
4
|
-
extend Sequel::Deprecation
|
5
|
-
|
6
|
-
# Check the Model.associate method to remove the :from option
|
7
|
-
|
8
|
-
def self.is_dataset_magic_method?(m) #:nodoc:
|
9
|
-
method_name = m.to_s
|
10
|
-
Sequel::Dataset::MAGIC_METHODS.each_key do |r|
|
11
|
-
return true if method_name =~ r
|
12
|
-
end
|
13
|
-
false
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.method_missing(m, *args, &block) #:nodoc:
|
17
|
-
Thread.exclusive do
|
18
|
-
if dataset.respond_to?(m) || is_dataset_magic_method?(m)
|
19
|
-
instance_eval("def #{m}(*args, &block); deprecate('Sequel::Model.method_missing', 'Please define Sequel::Model.#{m} or use def_dataset_method :#{m}'); dataset.#{m}(*args, &block); end")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
respond_to?(m) ? send(m, *args, &block) : super(m, *args)
|
23
|
-
end
|
24
|
-
|
25
|
-
def method_missing(m, *args, &block) #:nodoc:
|
26
|
-
if m.to_s =~ /=\z/
|
27
|
-
attribute = m.to_s.chop
|
28
|
-
values.keys.each do |k|
|
29
|
-
next unless k.to_s == attribute
|
30
|
-
deprecate("Sequel::Model#method_missing", "Use model[:#{attribute}] = ...")
|
31
|
-
return self[attribute.to_sym] = args.first
|
32
|
-
end
|
33
|
-
super
|
34
|
-
else
|
35
|
-
attribute = m.to_s
|
36
|
-
values.keys.each do |k|
|
37
|
-
next unless k.to_s == attribute
|
38
|
-
deprecate("Sequel::Model#method_missing", "Use model[:#{attribute}]")
|
39
|
-
return self[attribute.to_sym]
|
40
|
-
end
|
41
|
-
super
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.create_with_params(params) #:nodoc:
|
46
|
-
deprecate("Sequel::Model.create_with_params", "Use .create")
|
47
|
-
create(params)
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.create_with(params) #:nodoc:
|
51
|
-
deprecate("Sequel::Model.create_with", "Use .create")
|
52
|
-
create(params)
|
53
|
-
end
|
54
|
-
|
55
|
-
def update_with(params) #:nodoc:
|
56
|
-
deprecate("Sequel::Model#update_with", "Use #update_with_params")
|
57
|
-
update_with_params(params)
|
58
|
-
end
|
59
|
-
|
60
|
-
def new_record? #:nodoc:
|
61
|
-
deprecate("Sequel::Model#new_record?", "Use #new?")
|
62
|
-
new?
|
63
|
-
end
|
64
|
-
|
65
|
-
def set(values) #:nodoc:
|
66
|
-
deprecate("Sequel::Model#set", "Use #update_values")
|
67
|
-
update_values(values)
|
68
|
-
end
|
69
|
-
|
70
|
-
def update(values) #:nodoc:
|
71
|
-
deprecate("Sequel::Model#update", "Use #update_values")
|
72
|
-
update_values(values)
|
73
|
-
end
|
74
|
-
|
75
|
-
# deprecated, please use many_to_one instead
|
76
|
-
def self.one_to_one(*args, &block) #:nodoc:
|
77
|
-
deprecate("Sequel::Model.one_to_one", "Use many_to_one")
|
78
|
-
many_to_one(*args, &block)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
Inflector.inflections do |inflect|
|
2
|
-
inflect.plural(/$/, 's')
|
3
|
-
inflect.plural(/s$/i, 's')
|
4
|
-
inflect.plural(/(ax|test)is$/i, '\1es')
|
5
|
-
inflect.plural(/(octop|vir)us$/i, '\1i')
|
6
|
-
inflect.plural(/(alias|status)$/i, '\1es')
|
7
|
-
inflect.plural(/(bu)s$/i, '\1ses')
|
8
|
-
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
|
9
|
-
inflect.plural(/([ti])um$/i, '\1a')
|
10
|
-
inflect.plural(/sis$/i, 'ses')
|
11
|
-
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
|
12
|
-
inflect.plural(/(hive)$/i, '\1s')
|
13
|
-
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
|
14
|
-
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
|
15
|
-
inflect.plural(/(matr|vert|ind)ix|ex$/i, '\1ices')
|
16
|
-
inflect.plural(/([m|l])ouse$/i, '\1ice')
|
17
|
-
inflect.plural(/^(ox)$/i, '\1en')
|
18
|
-
inflect.plural(/(quiz)$/i, '\1zes')
|
19
|
-
|
20
|
-
inflect.singular(/s$/i, '')
|
21
|
-
inflect.singular(/(n)ews$/i, '\1ews')
|
22
|
-
inflect.singular(/([ti])a$/i, '\1um')
|
23
|
-
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
|
24
|
-
inflect.singular(/(^analy)ses$/i, '\1sis')
|
25
|
-
inflect.singular(/([^f])ves$/i, '\1fe')
|
26
|
-
inflect.singular(/(hive)s$/i, '\1')
|
27
|
-
inflect.singular(/(tive)s$/i, '\1')
|
28
|
-
inflect.singular(/([lr])ves$/i, '\1f')
|
29
|
-
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
|
30
|
-
inflect.singular(/(s)eries$/i, '\1eries')
|
31
|
-
inflect.singular(/(m)ovies$/i, '\1ovie')
|
32
|
-
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
|
33
|
-
inflect.singular(/([m|l])ice$/i, '\1ouse')
|
34
|
-
inflect.singular(/(bus)es$/i, '\1')
|
35
|
-
inflect.singular(/(o)es$/i, '\1')
|
36
|
-
inflect.singular(/(shoe)s$/i, '\1')
|
37
|
-
inflect.singular(/(cris|ax|test)es$/i, '\1is')
|
38
|
-
inflect.singular(/(octop|vir)i$/i, '\1us')
|
39
|
-
inflect.singular(/(alias|status)es$/i, '\1')
|
40
|
-
inflect.singular(/^(ox)en/i, '\1')
|
41
|
-
inflect.singular(/(vert|ind)ices$/i, '\1ex')
|
42
|
-
inflect.singular(/(matr)ices$/i, '\1ix')
|
43
|
-
inflect.singular(/(quiz)zes$/i, '\1')
|
44
|
-
|
45
|
-
inflect.irregular('person', 'people')
|
46
|
-
inflect.irregular('man', 'men')
|
47
|
-
inflect.irregular('child', 'children')
|
48
|
-
inflect.irregular('sex', 'sexes')
|
49
|
-
inflect.irregular('move', 'moves')
|
50
|
-
|
51
|
-
inflect.uncountable(%w(equipment information rice money species series fish sheep))
|
52
|
-
end
|
53
|
-
|
54
|
-
module Inflections #:nodoc:
|
55
|
-
|
56
|
-
def pluralize
|
57
|
-
Inflector.pluralize(self)
|
58
|
-
end
|
59
|
-
|
60
|
-
def singularize
|
61
|
-
Inflector.singularize(self)
|
62
|
-
end
|
63
|
-
|
64
|
-
def camelize(first_letter = :upper)
|
65
|
-
case first_letter
|
66
|
-
when :upper then Inflector.camelize(self, true)
|
67
|
-
when :lower then Inflector.camelize(self, false)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
alias_method :camelcase, :camelize
|
71
|
-
|
72
|
-
def titleize
|
73
|
-
Inflector.titleize(self)
|
74
|
-
end
|
75
|
-
alias_method :titlecase, :titleize
|
76
|
-
|
77
|
-
def underscore
|
78
|
-
Inflector.underscore(self)
|
79
|
-
end
|
80
|
-
|
81
|
-
def dasherize
|
82
|
-
Inflector.dasherize(self)
|
83
|
-
end
|
84
|
-
|
85
|
-
def demodulize
|
86
|
-
Inflector.demodulize(self)
|
87
|
-
end
|
88
|
-
|
89
|
-
def tableize
|
90
|
-
Inflector.tableize(self)
|
91
|
-
end
|
92
|
-
|
93
|
-
def classify
|
94
|
-
Inflector.classify(self)
|
95
|
-
end
|
96
|
-
|
97
|
-
def humanize
|
98
|
-
Inflector.humanize(self)
|
99
|
-
end
|
100
|
-
|
101
|
-
def foreign_key(separate_class_name_and_id_with_underscore = true)
|
102
|
-
Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
|
103
|
-
end
|
104
|
-
|
105
|
-
def constantize
|
106
|
-
Inflector.constantize(self)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
class String
|
111
|
-
include Inflections
|
112
|
-
end
|