sequel 5.39.0 → 5.72.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/CHANGELOG +408 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +59 -27
- data/bin/sequel +11 -3
- data/doc/advanced_associations.rdoc +16 -14
- data/doc/association_basics.rdoc +119 -24
- data/doc/cheat_sheet.rdoc +11 -3
- data/doc/mass_assignment.rdoc +1 -1
- data/doc/migration.rdoc +13 -6
- data/doc/model_hooks.rdoc +1 -1
- data/doc/object_model.rdoc +8 -8
- data/doc/opening_databases.rdoc +26 -12
- data/doc/postgresql.rdoc +16 -8
- data/doc/querying.rdoc +5 -3
- data/doc/release_notes/5.40.0.txt +40 -0
- data/doc/release_notes/5.41.0.txt +25 -0
- data/doc/release_notes/5.42.0.txt +136 -0
- data/doc/release_notes/5.43.0.txt +98 -0
- data/doc/release_notes/5.44.0.txt +32 -0
- data/doc/release_notes/5.45.0.txt +34 -0
- data/doc/release_notes/5.46.0.txt +87 -0
- data/doc/release_notes/5.47.0.txt +59 -0
- data/doc/release_notes/5.48.0.txt +14 -0
- data/doc/release_notes/5.49.0.txt +59 -0
- data/doc/release_notes/5.50.0.txt +78 -0
- data/doc/release_notes/5.51.0.txt +47 -0
- data/doc/release_notes/5.52.0.txt +87 -0
- data/doc/release_notes/5.53.0.txt +23 -0
- data/doc/release_notes/5.54.0.txt +27 -0
- data/doc/release_notes/5.55.0.txt +21 -0
- data/doc/release_notes/5.56.0.txt +51 -0
- data/doc/release_notes/5.57.0.txt +23 -0
- data/doc/release_notes/5.58.0.txt +31 -0
- data/doc/release_notes/5.59.0.txt +73 -0
- data/doc/release_notes/5.60.0.txt +22 -0
- data/doc/release_notes/5.61.0.txt +43 -0
- data/doc/release_notes/5.62.0.txt +132 -0
- data/doc/release_notes/5.63.0.txt +33 -0
- data/doc/release_notes/5.64.0.txt +50 -0
- data/doc/release_notes/5.65.0.txt +21 -0
- data/doc/release_notes/5.66.0.txt +24 -0
- data/doc/release_notes/5.67.0.txt +32 -0
- data/doc/release_notes/5.68.0.txt +61 -0
- data/doc/release_notes/5.69.0.txt +26 -0
- data/doc/release_notes/5.70.0.txt +35 -0
- data/doc/release_notes/5.71.0.txt +21 -0
- data/doc/release_notes/5.72.0.txt +33 -0
- data/doc/schema_modification.rdoc +1 -1
- data/doc/security.rdoc +9 -9
- data/doc/sharding.rdoc +3 -1
- data/doc/sql.rdoc +28 -16
- data/doc/testing.rdoc +22 -11
- data/doc/transactions.rdoc +6 -6
- data/doc/virtual_rows.rdoc +2 -2
- data/lib/sequel/adapters/ado/access.rb +1 -1
- data/lib/sequel/adapters/ado.rb +17 -17
- data/lib/sequel/adapters/amalgalite.rb +3 -5
- data/lib/sequel/adapters/ibmdb.rb +2 -2
- data/lib/sequel/adapters/jdbc/derby.rb +8 -0
- data/lib/sequel/adapters/jdbc/h2.rb +60 -10
- data/lib/sequel/adapters/jdbc/hsqldb.rb +6 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +7 -4
- data/lib/sequel/adapters/jdbc.rb +16 -18
- data/lib/sequel/adapters/mysql.rb +92 -67
- data/lib/sequel/adapters/mysql2.rb +54 -49
- data/lib/sequel/adapters/odbc.rb +6 -2
- data/lib/sequel/adapters/oracle.rb +4 -3
- data/lib/sequel/adapters/postgres.rb +83 -40
- data/lib/sequel/adapters/shared/access.rb +11 -1
- data/lib/sequel/adapters/shared/db2.rb +30 -0
- data/lib/sequel/adapters/shared/mssql.rb +90 -9
- data/lib/sequel/adapters/shared/mysql.rb +47 -2
- data/lib/sequel/adapters/shared/oracle.rb +82 -1
- data/lib/sequel/adapters/shared/postgres.rb +496 -178
- data/lib/sequel/adapters/shared/sqlanywhere.rb +11 -1
- data/lib/sequel/adapters/shared/sqlite.rb +116 -11
- data/lib/sequel/adapters/sqlanywhere.rb +1 -1
- data/lib/sequel/adapters/sqlite.rb +60 -18
- data/lib/sequel/adapters/tinytds.rb +1 -1
- data/lib/sequel/adapters/trilogy.rb +117 -0
- data/lib/sequel/adapters/utils/columns_limit_1.rb +22 -0
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/ast_transformer.rb +6 -0
- data/lib/sequel/connection_pool/sharded_single.rb +5 -7
- data/lib/sequel/connection_pool/sharded_threaded.rb +16 -11
- data/lib/sequel/connection_pool/sharded_timed_queue.rb +374 -0
- data/lib/sequel/connection_pool/single.rb +6 -8
- data/lib/sequel/connection_pool/threaded.rb +14 -8
- data/lib/sequel/connection_pool/timed_queue.rb +270 -0
- data/lib/sequel/connection_pool.rb +55 -31
- data/lib/sequel/core.rb +28 -18
- data/lib/sequel/database/connecting.rb +27 -3
- data/lib/sequel/database/dataset.rb +16 -6
- data/lib/sequel/database/misc.rb +69 -14
- data/lib/sequel/database/query.rb +73 -2
- data/lib/sequel/database/schema_generator.rb +46 -53
- data/lib/sequel/database/schema_methods.rb +18 -2
- data/lib/sequel/dataset/actions.rb +108 -14
- data/lib/sequel/dataset/deprecated_singleton_class_methods.rb +42 -0
- data/lib/sequel/dataset/features.rb +20 -0
- data/lib/sequel/dataset/misc.rb +12 -2
- data/lib/sequel/dataset/placeholder_literalizer.rb +20 -9
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/query.rb +171 -44
- data/lib/sequel/dataset/sql.rb +182 -47
- data/lib/sequel/dataset.rb +4 -0
- data/lib/sequel/extensions/_model_pg_row.rb +0 -12
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/any_not_empty.rb +1 -1
- data/lib/sequel/extensions/async_thread_pool.rb +439 -0
- data/lib/sequel/extensions/auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/blank.rb +8 -0
- data/lib/sequel/extensions/connection_expiration.rb +15 -9
- data/lib/sequel/extensions/connection_validator.rb +16 -11
- data/lib/sequel/extensions/constraint_validations.rb +1 -1
- data/lib/sequel/extensions/core_refinements.rb +36 -11
- data/lib/sequel/extensions/date_arithmetic.rb +71 -31
- data/lib/sequel/extensions/date_parse_input_handler.rb +67 -0
- data/lib/sequel/extensions/datetime_parse_to_time.rb +5 -1
- data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
- data/lib/sequel/extensions/eval_inspect.rb +2 -0
- data/lib/sequel/extensions/index_caching.rb +5 -1
- data/lib/sequel/extensions/inflector.rb +9 -1
- data/lib/sequel/extensions/is_distinct_from.rb +141 -0
- data/lib/sequel/extensions/looser_typecasting.rb +3 -0
- data/lib/sequel/extensions/migration.rb +11 -2
- data/lib/sequel/extensions/named_timezones.rb +26 -6
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +32 -4
- data/lib/sequel/extensions/pg_array_ops.rb +2 -2
- data/lib/sequel/extensions/pg_auto_parameterize.rb +509 -0
- data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +110 -0
- data/lib/sequel/extensions/pg_enum.rb +2 -3
- data/lib/sequel/extensions/pg_extended_date_support.rb +38 -27
- data/lib/sequel/extensions/pg_extended_integer_support.rb +116 -0
- data/lib/sequel/extensions/pg_hstore.rb +6 -1
- data/lib/sequel/extensions/pg_hstore_ops.rb +53 -3
- data/lib/sequel/extensions/pg_inet.rb +10 -11
- data/lib/sequel/extensions/pg_inet_ops.rb +1 -1
- data/lib/sequel/extensions/pg_interval.rb +45 -19
- data/lib/sequel/extensions/pg_json.rb +13 -15
- data/lib/sequel/extensions/pg_json_ops.rb +73 -2
- data/lib/sequel/extensions/pg_loose_count.rb +3 -1
- data/lib/sequel/extensions/pg_multirange.rb +367 -0
- data/lib/sequel/extensions/pg_range.rb +11 -24
- data/lib/sequel/extensions/pg_range_ops.rb +37 -9
- data/lib/sequel/extensions/pg_row.rb +21 -19
- data/lib/sequel/extensions/pg_row_ops.rb +1 -1
- data/lib/sequel/extensions/query.rb +2 -0
- data/lib/sequel/extensions/s.rb +2 -1
- data/lib/sequel/extensions/schema_caching.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +45 -11
- data/lib/sequel/extensions/server_block.rb +10 -13
- data/lib/sequel/extensions/set_literalizer.rb +58 -0
- data/lib/sequel/extensions/sql_comments.rb +110 -3
- data/lib/sequel/extensions/sql_log_normalizer.rb +108 -0
- data/lib/sequel/extensions/sqlite_json_ops.rb +255 -0
- data/lib/sequel/extensions/string_agg.rb +1 -1
- data/lib/sequel/extensions/string_date_time.rb +19 -23
- data/lib/sequel/extensions/symbol_aref.rb +2 -0
- data/lib/sequel/model/associations.rb +345 -101
- data/lib/sequel/model/base.rb +51 -27
- data/lib/sequel/model/dataset_module.rb +3 -0
- data/lib/sequel/model/errors.rb +10 -1
- data/lib/sequel/model/inflections.rb +1 -1
- data/lib/sequel/model/plugins.rb +5 -0
- data/lib/sequel/plugins/association_proxies.rb +2 -0
- data/lib/sequel/plugins/async_thread_pool.rb +39 -0
- data/lib/sequel/plugins/auto_restrict_eager_graph.rb +62 -0
- data/lib/sequel/plugins/auto_validations.rb +87 -15
- data/lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb +68 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/column_encryption.rb +728 -0
- data/lib/sequel/plugins/composition.rb +10 -4
- data/lib/sequel/plugins/concurrent_eager_loading.rb +174 -0
- data/lib/sequel/plugins/constraint_validations.rb +10 -6
- data/lib/sequel/plugins/dataset_associations.rb +4 -1
- data/lib/sequel/plugins/defaults_setter.rb +16 -0
- data/lib/sequel/plugins/dirty.rb +1 -1
- data/lib/sequel/plugins/enum.rb +124 -0
- data/lib/sequel/plugins/finder.rb +4 -2
- data/lib/sequel/plugins/insert_conflict.rb +4 -0
- data/lib/sequel/plugins/instance_specific_default.rb +1 -1
- data/lib/sequel/plugins/json_serializer.rb +39 -24
- data/lib/sequel/plugins/lazy_attributes.rb +3 -0
- data/lib/sequel/plugins/list.rb +3 -1
- data/lib/sequel/plugins/many_through_many.rb +109 -10
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +8 -38
- data/lib/sequel/plugins/nested_attributes.rb +12 -7
- data/lib/sequel/plugins/optimistic_locking.rb +9 -42
- data/lib/sequel/plugins/optimistic_locking_base.rb +55 -0
- data/lib/sequel/plugins/pg_array_associations.rb +56 -38
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +11 -3
- data/lib/sequel/plugins/pg_xmin_optimistic_locking.rb +109 -0
- data/lib/sequel/plugins/prepared_statements.rb +12 -2
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -1
- data/lib/sequel/plugins/primary_key_lookup_check_values.rb +154 -0
- data/lib/sequel/plugins/rcte_tree.rb +27 -19
- data/lib/sequel/plugins/require_valid_schema.rb +67 -0
- data/lib/sequel/plugins/serialization.rb +9 -3
- data/lib/sequel/plugins/serialization_modification_detection.rb +2 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -0
- data/lib/sequel/plugins/sql_comments.rb +189 -0
- data/lib/sequel/plugins/static_cache.rb +39 -1
- data/lib/sequel/plugins/static_cache_cache.rb +5 -1
- data/lib/sequel/plugins/subclasses.rb +28 -11
- data/lib/sequel/plugins/tactical_eager_loading.rb +23 -10
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/unused_associations.rb +521 -0
- data/lib/sequel/plugins/update_or_create.rb +1 -1
- data/lib/sequel/plugins/validate_associated.rb +22 -12
- data/lib/sequel/plugins/validation_helpers.rb +46 -12
- data/lib/sequel/plugins/validation_helpers_generic_type_messages.rb +73 -0
- data/lib/sequel/plugins/xml_serializer.rb +1 -1
- data/lib/sequel/sql.rb +1 -1
- data/lib/sequel/timezones.rb +12 -14
- data/lib/sequel/version.rb +1 -1
- metadata +132 -38
@@ -36,6 +36,7 @@ module Sequel
|
|
36
36
|
# :message :: The message to use. Can be a string which is used directly, or a
|
37
37
|
# proc which is called. If the validation method takes a argument before the array of attributes,
|
38
38
|
# that argument is passed as an argument to the proc.
|
39
|
+
# :skip_invalid :: Do not try to validate columns that are already invalid.
|
39
40
|
#
|
40
41
|
# The default validation options for all models can be modified by
|
41
42
|
# overridding the Model#default_validation_helpers_options private method.
|
@@ -65,18 +66,19 @@ module Sequel
|
|
65
66
|
# integer: "is not a number"
|
66
67
|
#
|
67
68
|
# Note that if you want to support internationalization of Errors#full_messages,
|
68
|
-
#
|
69
|
+
# it is easiest to override Errors#full_message (note singular form and not plural form).
|
70
|
+
# Here's an example:
|
69
71
|
#
|
70
72
|
# class Sequel::Model::Errors
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
# att.is_a?(Array) ? Array(att).map!{|v| I18n.t("attributes.#{v}")} : att = I18n.t("attributes.#{att}")
|
75
|
-
# errors.each {|e| m << (e.is_a?(LiteralString) ? e : "#{Array(att).join(I18n.t('errors.joiner'))} #{e}")}
|
76
|
-
# m
|
77
|
-
# end
|
73
|
+
# private
|
74
|
+
# def full_message(attribute, error_msg)
|
75
|
+
# "#{Array(attribute).join(I18n.t('errors.joiner'))} #{error_msg}"
|
78
76
|
# end
|
79
77
|
# end
|
78
|
+
#
|
79
|
+
# It is recommended that users of this plugin that use validates_schema_types also use
|
80
|
+
# the validation_helpers_generic_type_messages plugin for more useful type validation
|
81
|
+
# failure messages.
|
80
82
|
module ValidationHelpers
|
81
83
|
DEFAULT_OPTIONS = {
|
82
84
|
:exact_length=>{:message=>lambda{|exact| "is not #{exact} characters"}},
|
@@ -85,8 +87,11 @@ module Sequel
|
|
85
87
|
:integer=>{:message=>lambda{"is not a number"}},
|
86
88
|
:length_range=>{:message=>lambda{|range| "is too short or too long"}},
|
87
89
|
:max_length=>{:message=>lambda{|max| "is longer than #{max} characters"}, :nil_message=>lambda{"is not present"}},
|
90
|
+
:max_value=>{:message=>lambda{|max| "is greater than maximum allowed value"}},
|
88
91
|
:min_length=>{:message=>lambda{|min| "is shorter than #{min} characters"}},
|
92
|
+
:min_value=>{:message=>lambda{|min| "is less than minimum allowed value"}},
|
89
93
|
:not_null=>{:message=>lambda{"is not present"}},
|
94
|
+
:no_null_byte=>{:message=>lambda{"contains a null byte"}},
|
90
95
|
:numeric=>{:message=>lambda{"is not a number"}},
|
91
96
|
:operator=>{:message=>lambda{|operator, rhs| "is not #{operator} #{rhs}"}},
|
92
97
|
:type=>{:message=>lambda{|klass| klass.is_a?(Array) ? "is not a valid #{klass.join(" or ").downcase}" : "is not a valid #{klass.to_s.downcase}"}},
|
@@ -142,15 +147,38 @@ module Sequel
|
|
142
147
|
end
|
143
148
|
end
|
144
149
|
|
150
|
+
# Check that the attribute values are not greater that the given maximum value.
|
151
|
+
# Does not perform validation if attribute value is nil.
|
152
|
+
# You should only call this if you have checked the attribute value has the expected type.
|
153
|
+
def validates_max_value(max, atts, opts=OPTS)
|
154
|
+
validatable_attributes_for_type(:max_value, atts, opts) do |a,v,m|
|
155
|
+
validation_error_message(m, max) if !v.nil? && v > max
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
145
159
|
# Check that the attribute values are not shorter than the given min length.
|
146
160
|
def validates_min_length(min, atts, opts=OPTS)
|
147
161
|
validatable_attributes_for_type(:min_length, atts, opts){|a,v,m| validation_error_message(m, min) if v.nil? || v.length < min}
|
148
162
|
end
|
149
163
|
|
164
|
+
# Check that the attribute values are not less that the given minimum value.
|
165
|
+
# Does not perform validation if attribute value is nil.
|
166
|
+
# You should only call this if you have checked the attribute value has the expected type.
|
167
|
+
def validates_min_value(min, atts, opts=OPTS)
|
168
|
+
validatable_attributes_for_type(:min_value, atts, opts) do |a,v,m|
|
169
|
+
validation_error_message(m, min) if !v.nil? && v < min
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
150
173
|
# Check attribute value(s) are not NULL/nil.
|
151
174
|
def validates_not_null(atts, opts=OPTS)
|
152
175
|
validatable_attributes_for_type(:not_null, atts, opts){|a,v,m| validation_error_message(m) if v.nil?}
|
153
176
|
end
|
177
|
+
|
178
|
+
# Check attribute value(s) does not contain a null ("\0", ASCII NUL) byte.
|
179
|
+
def validates_no_null_byte(atts, opts=OPTS)
|
180
|
+
validatable_attributes_for_type(:no_null_byte, atts, opts){|a,v,m| validation_error_message(m) if String === v && v.include?("\0")}
|
181
|
+
end
|
154
182
|
|
155
183
|
# Check attribute value(s) string representation is a valid float.
|
156
184
|
def validates_numeric(atts, opts=OPTS)
|
@@ -187,7 +215,7 @@ module Sequel
|
|
187
215
|
klass = klass.to_s.constantize if klass.is_a?(String) || klass.is_a?(Symbol)
|
188
216
|
validatable_attributes_for_type(:type, atts, opts) do |a,v,m|
|
189
217
|
if klass.is_a?(Array) ? !klass.any?{|kls| v.is_a?(kls)} : !v.is_a?(klass)
|
190
|
-
|
218
|
+
validates_type_error_message(m, klass)
|
191
219
|
end
|
192
220
|
end
|
193
221
|
end
|
@@ -262,7 +290,7 @@ module Sequel
|
|
262
290
|
next if vals.any?(&:nil?)
|
263
291
|
ds.where(arr.zip(vals))
|
264
292
|
end
|
265
|
-
ds = yield(ds) if
|
293
|
+
ds = yield(ds) if defined?(yield)
|
266
294
|
unless new?
|
267
295
|
h = ds.joined_dataset? ? qualified_pk_hash : pk_hash
|
268
296
|
ds = ds.exclude(h)
|
@@ -281,14 +309,17 @@ module Sequel
|
|
281
309
|
DEFAULT_OPTIONS[type]
|
282
310
|
end
|
283
311
|
|
284
|
-
# Skip validating any attribute that matches one of the allow_* options
|
312
|
+
# Skip validating any attribute that matches one of the allow_* options,
|
313
|
+
# or already has an error if the skip_invalid option is given.
|
314
|
+
#
|
285
315
|
# Otherwise, yield the attribute, value, and passed option :message to
|
286
316
|
# the block. If the block returns anything except nil or false, add it as
|
287
317
|
# an error message for that attributes.
|
288
318
|
def validatable_attributes(atts, opts)
|
289
|
-
am, an, ab, m = opts.values_at(:allow_missing, :allow_nil, :allow_blank, :message)
|
319
|
+
am, an, ab, m, si = opts.values_at(:allow_missing, :allow_nil, :allow_blank, :message, :skip_invalid)
|
290
320
|
from_values = opts[:from] == :values
|
291
321
|
Array(atts).each do |a|
|
322
|
+
next if si && errors.on(a)
|
292
323
|
next if am && !values.has_key?(a)
|
293
324
|
v = from_values ? values[a] : get_column_value(a)
|
294
325
|
next if an && v.nil?
|
@@ -311,6 +342,9 @@ module Sequel
|
|
311
342
|
def validation_error_message(message, *args)
|
312
343
|
message.is_a?(Proc) ? message.call(*args) : message
|
313
344
|
end
|
345
|
+
|
346
|
+
# The validation error message for type validations, for the given class.
|
347
|
+
alias validates_type_error_message validation_error_message
|
314
348
|
end
|
315
349
|
end
|
316
350
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require_relative 'validation_helpers'
|
4
|
+
|
5
|
+
module Sequel
|
6
|
+
module Plugins
|
7
|
+
# The validation_helpers_generic_type_messages plugin overrides the default
|
8
|
+
# type validation failure messages in the validation_helpers plugin to be
|
9
|
+
# more generic and understandable by the average user, instead of always
|
10
|
+
# be based on the names of the allowed classes for the type. For example:
|
11
|
+
#
|
12
|
+
# # :blob type
|
13
|
+
# # validation_helpers default: "value is not a valid sequel::sql::blob"
|
14
|
+
# # with this plugin: "value is not a blob"
|
15
|
+
#
|
16
|
+
# # :boolean type
|
17
|
+
# # validation_helpers default: "value is not a valid trueclass or falseclass"
|
18
|
+
# # with this plugin: "value is not true or false"
|
19
|
+
#
|
20
|
+
# # :datetime type
|
21
|
+
# # validation_helpers default: "value is not a valid time or datetime"
|
22
|
+
# # with this plugin: "value is not a valid timestamp"
|
23
|
+
#
|
24
|
+
# # custom/database-specific types
|
25
|
+
# # validation_helpers default: "value is not a valid sequel::class_name"
|
26
|
+
# # with this plugin: "value is not the expected type"
|
27
|
+
#
|
28
|
+
# It is expected that this plugin will become the default behavior of
|
29
|
+
# validation_helpers in Sequel 6.
|
30
|
+
#
|
31
|
+
# To enable this the use of generic type messages for all models, load this
|
32
|
+
# plugin into Sequel::Model.
|
33
|
+
#
|
34
|
+
# Sequel::Model.plugin :validation_helpers_generic_type_messages
|
35
|
+
module ValidationHelpersGenericTypeMessages
|
36
|
+
OVERRIDE_PROC = ValidationHelpers::DEFAULT_OPTIONS[:type][:message]
|
37
|
+
private_constant :OVERRIDE_PROC
|
38
|
+
|
39
|
+
TYPE_ERROR_STRINGS = {
|
40
|
+
String => 'is not a string'.freeze,
|
41
|
+
Integer => 'is not an integer'.freeze,
|
42
|
+
Date => 'is not a valid date'.freeze,
|
43
|
+
[Time, DateTime].freeze => 'is not a valid timestamp'.freeze,
|
44
|
+
Sequel::SQLTime => 'is not a valid time'.freeze,
|
45
|
+
[TrueClass, FalseClass].freeze => 'is not true or false'.freeze,
|
46
|
+
Float => 'is not a number'.freeze,
|
47
|
+
BigDecimal => 'is not a number'.freeze,
|
48
|
+
Sequel::SQL::Blob => 'is not a blob'.freeze,
|
49
|
+
}
|
50
|
+
TYPE_ERROR_STRINGS.default = "is not the expected type".freeze
|
51
|
+
TYPE_ERROR_STRINGS.freeze
|
52
|
+
private_constant :TYPE_ERROR_STRINGS
|
53
|
+
|
54
|
+
def self.apply(mod)
|
55
|
+
mod.plugin :validation_helpers
|
56
|
+
end
|
57
|
+
|
58
|
+
module InstanceMethods
|
59
|
+
private
|
60
|
+
|
61
|
+
# Use a generic error message for type validations.
|
62
|
+
def validates_type_error_message(m, klass)
|
63
|
+
# SEQUEL6: Make this the default behavior in validation_helpers
|
64
|
+
if OVERRIDE_PROC.equal?(m)
|
65
|
+
TYPE_ERROR_STRINGS[klass]
|
66
|
+
else
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/sequel/sql.rb
CHANGED
data/lib/sequel/timezones.rb
CHANGED
@@ -82,22 +82,20 @@ module Sequel
|
|
82
82
|
# +application_timezone+ using +convert_input_timestamp+ and
|
83
83
|
# +convert_output_timestamp+.
|
84
84
|
def convert_timestamp(v, input_timezone)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
DateTime.civil(v.year, v.month, v.day, 0, 0, 0, application_timezone == :local ? Rational(Time.local(v.year, v.month, v.day).utc_offset, 86400) : 0)
|
90
|
-
else
|
91
|
-
Time.public_send(application_timezone == :utc ? :utc : :local, v.year, v.month, v.day)
|
92
|
-
end
|
85
|
+
if v.is_a?(Date) && !v.is_a?(DateTime)
|
86
|
+
# Dates handled specially as they are assumed to already be in the application_timezone
|
87
|
+
if datetime_class == DateTime
|
88
|
+
DateTime.civil(v.year, v.month, v.day, 0, 0, 0, application_timezone == :local ? Rational(Time.local(v.year, v.month, v.day).utc_offset, 86400) : 0)
|
93
89
|
else
|
94
|
-
|
90
|
+
Time.public_send(application_timezone == :utc ? :utc : :local, v.year, v.month, v.day)
|
95
91
|
end
|
96
|
-
|
97
|
-
|
98
|
-
rescue => e
|
99
|
-
raise convert_exception_class(e, InvalidValue)
|
92
|
+
else
|
93
|
+
convert_output_timestamp(convert_input_timestamp(v, input_timezone), application_timezone)
|
100
94
|
end
|
95
|
+
rescue InvalidValue
|
96
|
+
raise
|
97
|
+
rescue => e
|
98
|
+
raise convert_exception_class(e, InvalidValue)
|
101
99
|
end
|
102
100
|
|
103
101
|
# Convert the given object into an object of <tt>Sequel.datetime_class</tt> in the
|
@@ -158,7 +156,7 @@ module Sequel
|
|
158
156
|
case v
|
159
157
|
when String
|
160
158
|
v2 = Sequel.string_to_datetime(v)
|
161
|
-
if !input_timezone ||
|
159
|
+
if !input_timezone || _date_parse(v).has_key?(:offset)
|
162
160
|
v2
|
163
161
|
else
|
164
162
|
# Correct for potentially wrong offset if string doesn't include offset
|
data/lib/sequel/version.rb
CHANGED
@@ -6,7 +6,7 @@ module Sequel
|
|
6
6
|
|
7
7
|
# The minor version of Sequel. Bumped for every non-patch level
|
8
8
|
# release, generally around once a month.
|
9
|
-
MINOR =
|
9
|
+
MINOR = 72
|
10
10
|
|
11
11
|
# The tiny version of Sequel. Usually 0, only bumped for bugfix
|
12
12
|
# releases that fix regressions from previous versions.
|