sequel 2.12.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/CHANGELOG +62 -0
  2. data/README.rdoc +3 -3
  3. data/Rakefile +7 -0
  4. data/doc/advanced_associations.rdoc +44 -0
  5. data/doc/release_notes/3.0.0.txt +221 -0
  6. data/lib/sequel/adapters/amalgalite.rb +208 -0
  7. data/lib/sequel/adapters/db2.rb +3 -0
  8. data/lib/sequel/adapters/dbi.rb +9 -0
  9. data/lib/sequel/adapters/do.rb +0 -4
  10. data/lib/sequel/adapters/firebird.rb +16 -18
  11. data/lib/sequel/adapters/informix.rb +5 -3
  12. data/lib/sequel/adapters/jdbc.rb +24 -20
  13. data/lib/sequel/adapters/jdbc/h2.rb +15 -4
  14. data/lib/sequel/adapters/mysql.rb +4 -8
  15. data/lib/sequel/adapters/odbc.rb +0 -4
  16. data/lib/sequel/adapters/oracle.rb +0 -4
  17. data/lib/sequel/adapters/shared/mssql.rb +16 -5
  18. data/lib/sequel/adapters/shared/mysql.rb +87 -86
  19. data/lib/sequel/adapters/shared/oracle.rb +92 -3
  20. data/lib/sequel/adapters/shared/postgres.rb +85 -29
  21. data/lib/sequel/adapters/shared/progress.rb +8 -3
  22. data/lib/sequel/adapters/shared/sqlite.rb +53 -23
  23. data/lib/sequel/adapters/sqlite.rb +4 -7
  24. data/lib/sequel/adapters/utils/unsupported.rb +3 -3
  25. data/lib/sequel/connection_pool.rb +18 -25
  26. data/lib/sequel/core.rb +2 -21
  27. data/lib/sequel/database.rb +60 -44
  28. data/lib/sequel/database/schema_generator.rb +26 -31
  29. data/lib/sequel/database/schema_methods.rb +8 -3
  30. data/lib/sequel/database/schema_sql.rb +114 -28
  31. data/lib/sequel/dataset.rb +14 -41
  32. data/lib/sequel/dataset/convenience.rb +31 -54
  33. data/lib/sequel/dataset/graph.rb +7 -13
  34. data/lib/sequel/dataset/sql.rb +43 -54
  35. data/lib/sequel/extensions/inflector.rb +0 -5
  36. data/lib/sequel/extensions/schema_dumper.rb +238 -0
  37. data/lib/sequel/metaprogramming.rb +0 -20
  38. data/lib/sequel/model.rb +1 -2
  39. data/lib/sequel/model/base.rb +18 -16
  40. data/lib/sequel/model/inflections.rb +6 -9
  41. data/lib/sequel/plugins/caching.rb +0 -6
  42. data/lib/sequel/plugins/hook_class_methods.rb +1 -1
  43. data/lib/sequel/sql.rb +2 -0
  44. data/lib/sequel/version.rb +2 -2
  45. data/spec/adapters/firebird_spec.rb +35 -8
  46. data/spec/adapters/mysql_spec.rb +173 -266
  47. data/spec/adapters/oracle_spec.rb +13 -0
  48. data/spec/adapters/postgres_spec.rb +127 -227
  49. data/spec/adapters/sqlite_spec.rb +13 -171
  50. data/spec/core/connection_pool_spec.rb +15 -4
  51. data/spec/core/core_sql_spec.rb +14 -170
  52. data/spec/core/database_spec.rb +50 -132
  53. data/spec/core/dataset_spec.rb +47 -930
  54. data/spec/core/expression_filters_spec.rb +12 -0
  55. data/spec/core/schema_generator_spec.rb +37 -45
  56. data/spec/core/schema_spec.rb +26 -16
  57. data/spec/core/spec_helper.rb +0 -25
  58. data/spec/extensions/inflector_spec.rb +0 -3
  59. data/spec/extensions/schema_dumper_spec.rb +292 -0
  60. data/spec/extensions/serialization_spec.rb +9 -0
  61. data/spec/extensions/single_table_inheritance_spec.rb +6 -1
  62. data/spec/extensions/spec_helper.rb +1 -3
  63. data/spec/extensions/validation_helpers_spec.rb +4 -4
  64. data/spec/integration/database_test.rb +18 -0
  65. data/spec/integration/dataset_test.rb +112 -1
  66. data/spec/integration/eager_loader_test.rb +70 -9
  67. data/spec/integration/prepared_statement_test.rb +2 -2
  68. data/spec/integration/schema_test.rb +76 -27
  69. data/spec/integration/spec_helper.rb +0 -14
  70. data/spec/integration/transaction_test.rb +27 -0
  71. data/spec/model/associations_spec.rb +0 -36
  72. data/spec/model/base_spec.rb +18 -123
  73. data/spec/model/hooks_spec.rb +2 -235
  74. data/spec/model/inflector_spec.rb +15 -115
  75. data/spec/model/model_spec.rb +0 -120
  76. data/spec/model/plugins_spec.rb +0 -70
  77. data/spec/model/record_spec.rb +35 -93
  78. data/spec/model/spec_helper.rb +0 -27
  79. data/spec/model/validations_spec.rb +0 -931
  80. metadata +9 -14
  81. data/lib/sequel/deprecated.rb +0 -593
  82. data/lib/sequel/deprecated_migration.rb +0 -91
  83. data/lib/sequel/model/deprecated.rb +0 -204
  84. data/lib/sequel/model/deprecated_hooks.rb +0 -103
  85. data/lib/sequel/model/deprecated_inflector.rb +0 -335
  86. data/lib/sequel/model/deprecated_validations.rb +0 -388
  87. data/spec/core/core_ext_spec.rb +0 -156
  88. data/spec/core/migration_spec.rb +0 -263
  89. data/spec/core/pretty_table_spec.rb +0 -58
  90. data/spec/model/caching_spec.rb +0 -217
  91. data/spec/model/schema_spec.rb +0 -92
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-03 00:00:00 -07:00
12
+ date: 2009-05-04 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -48,6 +48,7 @@ extra_rdoc_files:
48
48
  - doc/release_notes/1.0.txt
49
49
  - doc/release_notes/2.11.0.txt
50
50
  - doc/release_notes/2.12.0.txt
51
+ - doc/release_notes/3.0.0.txt
51
52
  files:
52
53
  - COPYING
53
54
  - CHANGELOG
@@ -79,6 +80,7 @@ files:
79
80
  - doc/release_notes/1.0.txt
80
81
  - doc/release_notes/2.11.0.txt
81
82
  - doc/release_notes/2.12.0.txt
83
+ - doc/release_notes/3.0.0.txt
82
84
  - doc/virtual_rows.rdoc
83
85
  - spec/adapters
84
86
  - spec/adapters/ado_spec.rb
@@ -97,17 +99,15 @@ files:
97
99
  - spec/integration/spec_helper.rb
98
100
  - spec/integration/type_test.rb
99
101
  - spec/integration/transaction_test.rb
102
+ - spec/integration/database_test.rb
100
103
  - spec/rcov.opts
101
104
  - spec/core
102
105
  - spec/core/connection_pool_spec.rb
103
- - spec/core/core_ext_spec.rb
104
- - spec/core/core_sql_spec.rb
105
106
  - spec/core/database_spec.rb
107
+ - spec/core/core_sql_spec.rb
106
108
  - spec/core/dataset_spec.rb
107
109
  - spec/core/expression_filters_spec.rb
108
- - spec/core/migration_spec.rb
109
110
  - spec/core/object_graph_spec.rb
110
- - spec/core/pretty_table_spec.rb
111
111
  - spec/core/schema_generator_spec.rb
112
112
  - spec/core/schema_spec.rb
113
113
  - spec/core/spec_helper.rb
@@ -116,7 +116,6 @@ files:
116
116
  - spec/model/association_reflection_spec.rb
117
117
  - spec/model/associations_spec.rb
118
118
  - spec/model/base_spec.rb
119
- - spec/model/caching_spec.rb
120
119
  - spec/model/dataset_methods_spec.rb
121
120
  - spec/model/eager_loading_spec.rb
122
121
  - spec/model/hooks_spec.rb
@@ -124,7 +123,6 @@ files:
124
123
  - spec/model/model_spec.rb
125
124
  - spec/model/plugins_spec.rb
126
125
  - spec/model/record_spec.rb
127
- - spec/model/schema_spec.rb
128
126
  - spec/model/spec_helper.rb
129
127
  - spec/model/validations_spec.rb
130
128
  - spec/spec.opts
@@ -146,6 +144,7 @@ files:
146
144
  - spec/extensions/migration_spec.rb
147
145
  - spec/extensions/serialization_spec.rb
148
146
  - spec/extensions/validation_helpers_spec.rb
147
+ - spec/extensions/schema_dumper_spec.rb
149
148
  - lib/sequel.rb
150
149
  - lib/sequel_core.rb
151
150
  - lib/sequel_model.rb
@@ -166,6 +165,7 @@ files:
166
165
  - lib/sequel/extensions/pretty_table.rb
167
166
  - lib/sequel/extensions/blank.rb
168
167
  - lib/sequel/extensions/migration.rb
168
+ - lib/sequel/extensions/schema_dumper.rb
169
169
  - lib/sequel/adapters
170
170
  - lib/sequel/adapters/ado.rb
171
171
  - lib/sequel/adapters/db2.rb
@@ -201,6 +201,7 @@ files:
201
201
  - lib/sequel/adapters/utils/date_format.rb
202
202
  - lib/sequel/adapters/utils/stored_procedures.rb
203
203
  - lib/sequel/adapters/utils/unsupported.rb
204
+ - lib/sequel/adapters/amalgalite.rb
204
205
  - lib/sequel/connection_pool.rb
205
206
  - lib/sequel/core.rb
206
207
  - lib/sequel/core_sql.rb
@@ -215,24 +216,18 @@ files:
215
216
  - lib/sequel/dataset/prepared_statements.rb
216
217
  - lib/sequel/dataset/sql.rb
217
218
  - lib/sequel/dataset/graph.rb
218
- - lib/sequel/deprecated.rb
219
219
  - lib/sequel/exceptions.rb
220
220
  - lib/sequel/metaprogramming.rb
221
221
  - lib/sequel/model.rb
222
222
  - lib/sequel/model
223
223
  - lib/sequel/model/associations.rb
224
224
  - lib/sequel/model/base.rb
225
- - lib/sequel/model/deprecated.rb
226
- - lib/sequel/model/deprecated_hooks.rb
227
- - lib/sequel/model/deprecated_inflector.rb
228
- - lib/sequel/model/deprecated_validations.rb
229
225
  - lib/sequel/model/errors.rb
230
226
  - lib/sequel/model/exceptions.rb
231
227
  - lib/sequel/model/inflections.rb
232
228
  - lib/sequel/model/plugins.rb
233
229
  - lib/sequel/sql.rb
234
230
  - lib/sequel/version.rb
235
- - lib/sequel/deprecated_migration.rb
236
231
  has_rdoc: true
237
232
  homepage: http://sequel.rubyforge.org
238
233
  post_install_message:
@@ -1,593 +0,0 @@
1
- %w'bigdecimal/util enumerator yaml'.each do |f|
2
- require f
3
- end
4
-
5
- module Sequel
6
- # This module makes it easy to print deprecation warnings with optional backtraces to a given stream.
7
- # There are a couple of methods you can use to change where the deprecation methods are printed
8
- # and whether they should include backtraces:
9
- #
10
- # Sequel::Deprecation.output = $stderr # print deprecation messages to standard error (default)
11
- # Sequel::Deprecation.output = File.open('deprecated_calls.txt', 'wb') # use a file instead
12
- # Sequel::Deprecation.backtraces = false # don't include backtraces
13
- # Sequel::Deprecation.backtraces = true # include full backtraces
14
- # Sequel::Deprecation.backtraces = 10 # include 10 backtrace lines (default)
15
- # Sequel::Deprecation.backtraces = 1 # include 1 backtrace line
16
- module Deprecation
17
- extend Metaprogramming
18
-
19
- @output = $stderr
20
- @backtraces = 10
21
-
22
- metaattr_accessor :output, :backtraces
23
-
24
- # Print the message to the output stream
25
- def self.deprecate(method, instead=nil)
26
- message = instead ? "#{method} is deprecated and will be removed in Sequel 3.0. #{instead}." : method
27
- return unless output
28
- output.puts(message)
29
- case backtraces
30
- when Integer
31
- b = backtraces
32
- caller.each do |c|
33
- b -= 1
34
- output.puts(c)
35
- break if b == 0
36
- end
37
- when true
38
- caller.each{|c| output.puts(c)}
39
- end
40
- end
41
- end
42
-
43
- require 'deprecated_migration'
44
-
45
- def self.open(*args, &block)
46
- Deprecation.deprecate('Sequel.open', 'Use Sequel.connect')
47
- Database.connect(*args, &block)
48
- end
49
-
50
- def self.upcase_identifiers=(value)
51
- Deprecation.deprecate('Sequel.upcase_identifiers=', 'Use Sequel.identifier_input_method = :upcase or nil')
52
- Database.identifier_input_method = value ? :upcase : nil
53
- end
54
-
55
- def self.use_parse_tree
56
- Deprecation.deprecate('Sequel.use_parse_tree', 'Sequel has not used ParseTree since 2.2')
57
- false
58
- end
59
-
60
- def self.use_parse_tree=(val)
61
- Deprecation.deprecate('Sequel.use_parse_tree=', 'Sequel has not used ParseTree since 2.2')
62
- raise(Error, 'ParseTree support has been removed from Sequel') if val
63
- end
64
-
65
- class Database
66
- def self.upcase_identifiers=(value)
67
- Deprecation.deprecate('Sequel::Database.upcase_identifiers=', 'Use Sequel::Database.identifier_input_method = :upcase or nil')
68
- self.identifier_input_method = value ? :upcase : nil
69
- end
70
-
71
- def upcase_identifiers=(v)
72
- Deprecation.deprecate('Sequel::Database#upcase_identifiers=', 'Use Sequel::Database#identifier_input_method = :upcase or nil')
73
- self.identifier_input_method = v ? :upcase : nil
74
- end
75
-
76
- def upcase_identifiers?
77
- Deprecation.deprecate('Sequel::Database#upcase_identifiers?', 'Use Sequel::Database#identifier_input_method == :upcase')
78
- identifier_input_method == :upcase
79
- end
80
-
81
- def >>(*args, &block)
82
- Deprecation.deprecate('Sequel::Database#>>', 'Use Sequel::Database#fetch')
83
- fetch(*args, &block)
84
- end
85
-
86
- def query(&block)
87
- Deprecation.deprecate('Sequel::Database#query', 'require "sequel/extensions/query" first')
88
- dataset.query(&block)
89
- end
90
-
91
- def logger
92
- Deprecation.deprecate('Sequel::Database#logger', 'Use Sequel::Database#loggers')
93
- @loggers.first
94
- end
95
-
96
- def multi_threaded?
97
- Deprecation.deprecate('Sequel::Database#multi_threaded?', 'Use !database.single_threaded?')
98
- !@single_threaded
99
- end
100
- end
101
-
102
- class Dataset
103
- DATASET_CLASSES = []
104
- STOCK_TRANSFORMS = {
105
- :marshal => [
106
- # for backwards-compatibility we support also non-base64-encoded values.
107
- proc {|v| Marshal.load(v.unpack('m')[0]) rescue Marshal.load(v)},
108
- proc {|v| [Marshal.dump(v)].pack('m')}
109
- ],
110
- :yaml => [
111
- proc {|v| YAML.load v if v},
112
- proc {|v| v.to_yaml}
113
- ]
114
- }
115
-
116
- def self.dataset_classes
117
- Deprecation.deprecate('Sequel::Dataset#dataset_classes', 'No replacement is planned')
118
- DATASET_CLASSES
119
- end
120
-
121
- def self.inherited(c)
122
- DATASET_CLASSES << c
123
- end
124
-
125
- def upcase_identifiers=(v)
126
- Deprecation.deprecate('Sequel::Dataset#upcase_identifiers=', 'Use Sequel::Dataset#identifier_input_method = :upcase or nil')
127
- @identifier_input_method = v ? :upcase : nil
128
- end
129
-
130
- def upcase_identifiers?
131
- Deprecation.deprecate('Sequel::Dataset#upcase_identifiers?', 'Use Sequel::Dataset#identifier_input_method == :upcase')
132
- @identifier_input_method == :upcase
133
- end
134
-
135
- def model_classes
136
- Deprecation.deprecate('Sequel::Dataset#model_classes', 'Sequel::Model datasets no longer set this information')
137
- @opts[:models]
138
- end
139
-
140
- def polymorphic_key
141
- Deprecation.deprecate('Sequel::Dataset#polymorphic_key', 'Sequel::Model datasets no longer set this information')
142
- @opts[:polymorphic_key]
143
- end
144
-
145
- def set_model(key, *args)
146
- Deprecation.deprecate('Sequel::Dataset#set_model', 'Use Sequel::Dataset#set_row_proc with an appropriate row proc')
147
- # This code is more verbose then necessary for performance reasons
148
- case key
149
- when nil # set_model(nil) => no argument provided, so the dataset is denuded
150
- @opts.merge!(:naked => true, :models => nil, :polymorphic_key => nil)
151
- self.row_proc = nil
152
- when Class
153
- # isomorphic model
154
- @opts.merge!(:naked => nil, :models => {nil => key}, :polymorphic_key => nil)
155
- if key.respond_to?(:load)
156
- # the class has a values setter method, so we use it
157
- self.row_proc = proc{|h| key.load(h, *args)}
158
- else
159
- # otherwise we just pass the hash to the constructor
160
- self.row_proc = proc{|h| key.new(h, *args)}
161
- end
162
- when Symbol
163
- # polymorphic model
164
- hash = args.shift || raise(ArgumentError, "No class hash supplied for polymorphic model")
165
- @opts.merge!(:naked => true, :models => hash, :polymorphic_key => key)
166
- if (hash.empty? ? (hash[nil] rescue nil) : hash.values.first).respond_to?(:load)
167
- # the class has a values setter method, so we use it
168
- self.row_proc = proc do |h|
169
- c = hash[h[key]] || hash[nil] || \
170
- raise(Error, "No matching model class for record (#{polymorphic_key} => #{h[polymorphic_key].inspect})")
171
- c.load(h, *args)
172
- end
173
- else
174
- # otherwise we just pass the hash to the constructor
175
- self.row_proc = proc do |h|
176
- c = hash[h[key]] || hash[nil] || \
177
- raise(Error, "No matching model class for record (#{polymorphic_key} => #{h[polymorphic_key].inspect})")
178
- c.new(h, *args)
179
- end
180
- end
181
- else
182
- raise ArgumentError, "Invalid model specified"
183
- end
184
- self
185
- end
186
-
187
- def create_view(name)
188
- Sequel::Deprecation.deprecate('Sequel::Dataset#create_view', 'Use Sequel::Database#create_view')
189
- @db.create_view(name, self)
190
- end
191
-
192
- def create_or_replace_view(name)
193
- Sequel::Deprecation.deprecate('Sequel::Dataset#create_or_replace_view', 'Use Sequel::Database#create_or_replace_view')
194
- @db.create_or_replace_view(name, self)
195
- end
196
-
197
- def size
198
- Sequel::Deprecation.deprecate('Sequel::Dataset#size', 'Use Sequel::Dataset#count')
199
- count
200
- end
201
-
202
- def uniq(*args)
203
- Sequel::Deprecation.deprecate('Sequel::Dataset#uniq', 'Use Sequel::Dataset#distinct')
204
- distinct(*args)
205
- end
206
-
207
- def quote_column_ref(name)
208
- Sequel::Deprecation.deprecate('Sequel::Dataset#quote_column_ref', 'Use Sequel::Dataset#quote_identifier')
209
- quote_identifier(name)
210
- end
211
-
212
- def symbol_to_column_ref(sym)
213
- Sequel::Deprecation.deprecate('Sequel::Dataset#symbol_to_column_ref', 'Use Sequel::Dataset#literal')
214
- literal_symbol(sym)
215
- end
216
-
217
- def paginate(page_no, page_size, record_count=nil)
218
- Sequel::Deprecation.deprecate('Sequel::Dataset#paginate', 'require "sequel/extensions/pagination" first')
219
- require "sequel/extensions/pagination"
220
- raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit]
221
- paginated = limit(page_size, (page_no - 1) * page_size)
222
- paginated.extend(Pagination)
223
- paginated.set_pagination_info(page_no, page_size, record_count || count)
224
- end
225
-
226
- def each_page(page_size, &block)
227
- Sequel::Deprecation.deprecate('Sequel::Dataset#each_page', 'require "sequel/extensions/pagination" first')
228
- raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit]
229
- record_count = count
230
- total_pages = (record_count / page_size.to_f).ceil
231
- (1..total_pages).each{|page_no| yield paginate(page_no, page_size, record_count)}
232
- self
233
- end
234
-
235
- def query(&block)
236
- Sequel::Deprecation.deprecate('Sequel::Dataset#each_page', 'require "sequel/extensions/query" first')
237
- require "sequel/extensions/query"
238
- copy = clone({})
239
- copy.extend(QueryBlockCopy)
240
- copy.instance_eval(&block)
241
- clone(copy.opts)
242
- end
243
-
244
- def print(*cols)
245
- Sequel::Deprecation.deprecate('Sequel::Dataset#print', 'require "sequel/extensions/pretty_table" first')
246
- Sequel::PrettyTable.print(naked.all, cols.empty? ? columns : cols)
247
- end
248
-
249
- def transform(t)
250
- Sequel::Deprecation.deprecate('Sequel::Dataset#transform', 'There is no replacement.')
251
- @transform = t
252
- t.each do |k, v|
253
- case v
254
- when Array
255
- if (v.size != 2) || !v.first.is_a?(Proc) && !v.last.is_a?(Proc)
256
- raise Error::InvalidTransform, "Invalid transform specified"
257
- end
258
- else
259
- unless v = STOCK_TRANSFORMS[v]
260
- raise Error::InvalidTransform, "Invalid transform specified"
261
- else
262
- t[k] = v
263
- end
264
- end
265
- end
266
- self
267
- end
268
-
269
- def transform_load(r)
270
- r.inject({}) do |m, kv|
271
- k, v = *kv
272
- m[k] = (tt = @transform[k]) ? tt[0][v] : v
273
- m
274
- end
275
- end
276
-
277
- def transform_save(r)
278
- r.inject({}) do |m, kv|
279
- k, v = *kv
280
- m[k] = (tt = @transform[k]) ? tt[1][v] : v
281
- m
282
- end
283
- end
284
- end
285
-
286
- module SQL
287
- module CastMethods
288
- def cast_as(sql_type)
289
- Sequel::Deprecation.deprecate('Sequel::SQL::CastMethods#cast_as', 'Use Sequel::SQL::CastMethods#cast')
290
- cast(sql_type)
291
- end
292
- end
293
-
294
- class Blob
295
- def to_blob(*args)
296
- Sequel::Deprecation.deprecate('Sequel::SQL::Blob#to_blob', 'Use Sequel::SQL::Blob#to_sequel_blob')
297
- to_sequel_blob(*args)
298
- end
299
- end
300
- end
301
-
302
- module PrettyTable
303
- def self.print(*args)
304
- Sequel::Deprecation.deprecate('Sequel::PrettyTable#print', 'require "sequel/extensions/pretty_table" first')
305
- require "sequel/extensions/pretty_table"
306
- print(*args)
307
- end
308
- end
309
-
310
- class Error
311
- class InvalidStatement < Error; end
312
- class InvalidTransform < Error; end
313
- class NoExistingFilter < InvalidOperation; end
314
- end
315
- end
316
-
317
- if RUBY_VERSION < '1.9.0'
318
- class Hash
319
- unless method_defined?(:key)
320
- include(Module.new do
321
- def key(*args, &block)
322
- Sequel::Deprecation.deprecate('Hash#key', 'Use Hash#index')
323
- index(*args, &block)
324
- end
325
- end)
326
- end
327
- end
328
- end
329
-
330
- module Enumerable
331
- unless method_defined?(:send_each)
332
- def send_each(sym, *args)
333
- Sequel::Deprecation.deprecate('Enumerable#send_each', 'Use Enumerable#each{|x| x.send(...)}')
334
- each{|i| i.send(sym, *args)}
335
- end
336
- end
337
- end
338
-
339
- class Range
340
- unless method_defined?(:interval)
341
- include(Module.new do
342
- def interval
343
- Sequel::Deprecation.deprecate('Range#interval', 'Use range.first - range.last - (range.exclude_end? ? 1 : 0)')
344
- last - first - (exclude_end? ? 1 : 0)
345
- end
346
- end)
347
- end
348
- end
349
-
350
- class Array
351
- unless method_defined?(:extract_options!)
352
- include(Module.new do
353
- def extract_options!
354
- Sequel::Deprecation.deprecate('Array#extract_options!', 'Use array.last.is_a?(Hash) ? array.pop : {}')
355
- last.is_a?(Hash) ? pop : {}
356
- end
357
- end)
358
- end
359
-
360
- def to_sql
361
- Sequel::Deprecation.deprecate('Array#to_sql', 'It may be a good idea to refactor your implementation so this type of method is not required')
362
- map {|l| ((m = /^(.*)--/.match(l)) ? m[1] : l).chomp}.join(' '). \
363
- gsub(/\/\*.*\*\//, '').gsub(/\s+/, ' ').strip
364
- end
365
- end
366
-
367
- class String
368
- include(Module.new do
369
- def split_sql
370
- Sequel::Deprecation.deprecate('String#split_sql', 'It may be a good idea to refactor your implementation so this type of method is not required')
371
- to_sql.split(';').map {|s| s.strip}
372
- end
373
-
374
- def to_sql
375
- Sequel::Deprecation.deprecate('String#to_sql', 'It may be a good idea to refactor your implementation so this type of method is not required')
376
- split("\n").to_sql
377
- end
378
-
379
- def expr(*args)
380
- Sequel::Deprecation.deprecate('String#expr', 'Use String#lit')
381
- lit(*args)
382
- end
383
-
384
- unless String.method_defined?(:to_blob)
385
- def to_blob(*args)
386
- Sequel::Deprecation.deprecate('String#to_blob', 'Use String#to_sequel_blob')
387
- to_sequel_blob(*args)
388
- end
389
- end
390
-
391
- unless String.method_defined?(:blank?)
392
- def blank?
393
- Sequel::Deprecation.deprecate('String#blank?', "require 'sequel/extensions/blank' first")
394
- strip.empty?
395
- end
396
- end
397
-
398
- unless String.method_defined?(:to_date)
399
- def to_date
400
- Sequel::Deprecation.deprecate('String#to_date', 'You should require "sequel/extensions/string_date_time"')
401
- begin
402
- Date.parse(self, Sequel.convert_two_digit_years)
403
- rescue => e
404
- raise Sequel::Error::InvalidValue, "Invalid Date value '#{self}' (#{e.message})"
405
- end
406
- end
407
- end
408
-
409
- unless String.method_defined?(:to_datetime)
410
- def to_datetime
411
- Sequel::Deprecation.deprecate('String#to_datetime', 'You should require "sequel/extensions/string_date_time"')
412
- begin
413
- DateTime.parse(self, Sequel.convert_two_digit_years)
414
- rescue => e
415
- raise Sequel::Error::InvalidValue, "Invalid DateTime value '#{self}' (#{e.message})"
416
- end
417
- end
418
- end
419
-
420
- unless String.method_defined?(:to_sequel_time)
421
- def to_sequel_time
422
- Sequel::Deprecation.deprecate('String#to_sequel_time', 'You should require "sequel/extensions/string_date_time"')
423
- begin
424
- if Sequel.datetime_class == DateTime
425
- DateTime.parse(self, Sequel.convert_two_digit_years)
426
- else
427
- Sequel.datetime_class.parse(self)
428
- end
429
- rescue => e
430
- raise Sequel::Error::InvalidValue, "Invalid #{Sequel.datetime_class} value '#{self}' (#{e.message})"
431
- end
432
- end
433
- end
434
-
435
- unless String.method_defined?(:to_time)
436
- def to_time
437
- Sequel::Deprecation.deprecate('String#to_time', 'You should require "sequel/extensions/string_date_time"')
438
- begin
439
- Time.parse(self)
440
- rescue => e
441
- raise Sequel::Error::InvalidValue, "Invalid Time value '#{self}' (#{e.message})"
442
- end
443
- end
444
- end
445
- end)
446
- end
447
-
448
- class Symbol
449
- def |(sub)
450
- return super unless (Integer === sub) || ((Array === sub) && sub.any?{|x| Integer === x})
451
- Sequel::Deprecation.deprecate('The use of Symbol#| for SQL array subscripts', 'Use Symbol#sql_subscript')
452
- Sequel::SQL::Subscript.new(self, Array(sub))
453
- end
454
-
455
- def to_column_ref(ds)
456
- Sequel::Deprecation.deprecate('Symbol#to_column_ref', 'Use Dataset#literal')
457
- ds.literal(self)
458
- end
459
- end
460
-
461
- class Module
462
- include(Module.new do
463
- unless Module.method_defined?(:class_def)
464
- def class_def(name, &block)
465
- Sequel::Deprecation.deprecate('Object#class_def', "Install the metaid gem")
466
- class_eval{define_method(name, &block)}
467
- end
468
- end
469
-
470
- private
471
-
472
- unless Module.method_defined?(:class_attr_overridable)
473
- def class_attr_overridable(*meths)
474
- Sequel::Deprecation.deprecate('Module#class_attr_overridable', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
475
- meths.each{|meth| class_eval("def #{meth}; !defined?(@#{meth}) ? (@#{meth} = self.class.#{meth}) : @#{meth} end")}
476
- attr_writer(*meths)
477
- end
478
- end
479
-
480
- unless Module.method_defined?(:class_attr_reader)
481
- def class_attr_reader(*meths)
482
- Sequel::Deprecation.deprecate('Module#class_attr_reader', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
483
- meths.each{|meth| define_method(meth){self.class.send(meth)}}
484
- end
485
- end
486
-
487
- unless Module.method_defined?(:metaalias)
488
- def metaalias(to, from)
489
- Sequel::Deprecation.deprecate('Module#metaalias', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
490
- meta_eval{alias_method to, from}
491
- end
492
- end
493
-
494
- unless Module.method_defined?(:metaattr_accessor)
495
- def metaattr_accessor(*meths)
496
- Sequel::Deprecation.deprecate('Module#metaattr_accessor', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
497
- meta_eval{attr_accessor(*meths)}
498
- end
499
- end
500
-
501
- unless Module.method_defined?(:metaattr_reader)
502
- def metaattr_reader(*meths)
503
- Sequel::Deprecation.deprecate('Module#metaattr_reader', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
504
- meta_eval{attr_reader(*meths)}
505
- end
506
- end
507
- end)
508
- end
509
-
510
- class FalseClass
511
- unless method_defined?(:blank?)
512
- include(Module.new do
513
- def blank?
514
- Sequel::Deprecation.deprecate('FalseClass#blank?', "require 'sequel/extensions/blank' first")
515
- true
516
- end
517
- end)
518
- end
519
- end
520
-
521
- class NilClass
522
- unless method_defined?(:blank?)
523
- include(Module.new do
524
- def blank?
525
- Sequel::Deprecation.deprecate('NilClass#blank?', "require 'sequel/extensions/blank' first")
526
- true
527
- end
528
- end)
529
- end
530
- end
531
-
532
- class Numeric
533
- unless method_defined?(:blank?)
534
- include(Module.new do
535
- def blank?
536
- Sequel::Deprecation.deprecate('Numeric#blank?', "require 'sequel/extensions/blank' first")
537
- false
538
- end
539
- end)
540
- end
541
- end
542
-
543
- class TrueClass
544
- unless method_defined?(:blank?)
545
- include(Module.new do
546
- def blank?
547
- Sequel::Deprecation.deprecate('FalseClass#blank?', "require 'sequel/extensions/blank' first")
548
- false
549
- end
550
- end)
551
- end
552
- end
553
-
554
- class Object
555
- include(Module.new do
556
- unless Object.method_defined?(:blank?)
557
- def blank?
558
- Sequel::Deprecation.deprecate('FalseClass#blank?', "require 'sequel/extensions/blank' first")
559
- respond_to?(:empty?) && empty?
560
- end
561
- end
562
-
563
- unless Object.method_defined?(:is_one_of?)
564
- def is_one_of?(*classes)
565
- Sequel::Deprecation.deprecate('Object#is_one_of?', "Use classes.any?{|c| object.is_a?(c)}")
566
- classes.any?{|c| is_a?(c)}
567
- end
568
- end
569
-
570
- unless Object.method_defined?(:meta_def)
571
- def meta_def(name, &block)
572
- Sequel::Deprecation.deprecate('Object#meta_def', "Install the metaid gem")
573
- meta_eval{define_method(name, &block)}
574
- end
575
- end
576
-
577
- unless Object.method_defined?(:meta_eval)
578
- def meta_eval(&block)
579
- Sequel::Deprecation.deprecate('Object#meta_eval', "Install the metaid gem")
580
- metaclass.instance_eval(&block)
581
- end
582
- end
583
-
584
- unless Object.method_defined?(:metaclass)
585
- def metaclass
586
- Sequel::Deprecation.deprecate('Object#metaclass', "Install the metaid gem")
587
- class << self
588
- self
589
- end
590
- end
591
- end
592
- end)
593
- end