activerecord 4.1.8 → 4.2.11.3
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.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1165 -1591
- data/README.rdoc +15 -10
- data/lib/active_record/aggregations.rb +15 -8
- data/lib/active_record/association_relation.rb +13 -0
- data/lib/active_record/associations/alias_tracker.rb +3 -12
- data/lib/active_record/associations/association.rb +16 -4
- data/lib/active_record/associations/association_scope.rb +84 -43
- data/lib/active_record/associations/belongs_to_association.rb +28 -10
- data/lib/active_record/associations/builder/association.rb +16 -5
- data/lib/active_record/associations/builder/belongs_to.rb +7 -29
- data/lib/active_record/associations/builder/collection_association.rb +5 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +9 -14
- data/lib/active_record/associations/builder/has_many.rb +1 -1
- data/lib/active_record/associations/builder/has_one.rb +2 -2
- data/lib/active_record/associations/builder/singular_association.rb +8 -1
- data/lib/active_record/associations/collection_association.rb +87 -30
- data/lib/active_record/associations/collection_proxy.rb +33 -35
- data/lib/active_record/associations/foreign_association.rb +11 -0
- data/lib/active_record/associations/has_many_association.rb +83 -22
- data/lib/active_record/associations/has_many_through_association.rb +49 -26
- data/lib/active_record/associations/has_one_association.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +25 -15
- data/lib/active_record/associations/join_dependency/join_part.rb +0 -1
- data/lib/active_record/associations/join_dependency.rb +26 -12
- data/lib/active_record/associations/preloader/association.rb +14 -10
- data/lib/active_record/associations/preloader/through_association.rb +4 -3
- data/lib/active_record/associations/preloader.rb +37 -26
- data/lib/active_record/associations/singular_association.rb +17 -2
- data/lib/active_record/associations/through_association.rb +16 -12
- data/lib/active_record/associations.rb +158 -49
- data/lib/active_record/attribute.rb +163 -0
- data/lib/active_record/attribute_assignment.rb +20 -12
- data/lib/active_record/attribute_decorators.rb +66 -0
- data/lib/active_record/attribute_methods/before_type_cast.rb +7 -2
- data/lib/active_record/attribute_methods/dirty.rb +107 -43
- data/lib/active_record/attribute_methods/primary_key.rb +7 -8
- data/lib/active_record/attribute_methods/query.rb +1 -1
- data/lib/active_record/attribute_methods/read.rb +22 -59
- data/lib/active_record/attribute_methods/serialization.rb +16 -150
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +38 -28
- data/lib/active_record/attribute_methods/write.rb +9 -24
- data/lib/active_record/attribute_methods.rb +57 -95
- data/lib/active_record/attribute_set/builder.rb +106 -0
- data/lib/active_record/attribute_set.rb +81 -0
- data/lib/active_record/attributes.rb +147 -0
- data/lib/active_record/autosave_association.rb +30 -12
- data/lib/active_record/base.rb +13 -24
- data/lib/active_record/callbacks.rb +6 -6
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +85 -53
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +52 -50
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/quoting.rb +60 -60
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +39 -4
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +139 -57
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -34
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +271 -74
- data/lib/active_record/connection_adapters/abstract/transaction.rb +125 -118
- data/lib/active_record/connection_adapters/abstract_adapter.rb +177 -60
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +295 -141
- data/lib/active_record/connection_adapters/column.rb +29 -240
- data/lib/active_record/connection_adapters/connection_specification.rb +15 -24
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +17 -33
- data/lib/active_record/connection_adapters/mysql_adapter.rb +68 -145
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +15 -27
- data/lib/active_record/connection_adapters/postgresql/column.rb +20 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +40 -25
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +100 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +52 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +46 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +19 -0
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +21 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +59 -0
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +35 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +79 -0
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +19 -0
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +109 -0
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +21 -0
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +26 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +29 -385
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +46 -136
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +152 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +134 -43
- data/lib/active_record/connection_adapters/postgresql/utils.rb +77 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +224 -477
- data/lib/active_record/connection_adapters/schema_cache.rb +14 -28
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +61 -75
- data/lib/active_record/connection_handling.rb +1 -1
- data/lib/active_record/core.rb +163 -40
- data/lib/active_record/counter_cache.rb +60 -6
- data/lib/active_record/enum.rb +10 -12
- data/lib/active_record/errors.rb +53 -30
- data/lib/active_record/explain.rb +1 -1
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixtures.rb +62 -74
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +35 -10
- data/lib/active_record/integration.rb +4 -4
- data/lib/active_record/legacy_yaml_adapter.rb +30 -0
- data/lib/active_record/locking/optimistic.rb +46 -26
- data/lib/active_record/migration/command_recorder.rb +19 -2
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +79 -47
- data/lib/active_record/model_schema.rb +52 -58
- data/lib/active_record/nested_attributes.rb +18 -8
- data/lib/active_record/no_touching.rb +1 -1
- data/lib/active_record/persistence.rb +48 -27
- data/lib/active_record/query_cache.rb +3 -3
- data/lib/active_record/querying.rb +10 -7
- data/lib/active_record/railtie.rb +19 -14
- data/lib/active_record/railties/databases.rake +55 -56
- data/lib/active_record/readonly_attributes.rb +0 -1
- data/lib/active_record/reflection.rb +281 -117
- data/lib/active_record/relation/batches.rb +0 -1
- data/lib/active_record/relation/calculations.rb +41 -37
- data/lib/active_record/relation/delegation.rb +1 -1
- data/lib/active_record/relation/finder_methods.rb +71 -48
- data/lib/active_record/relation/merger.rb +39 -29
- data/lib/active_record/relation/predicate_builder/array_handler.rb +32 -13
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/predicate_builder.rb +42 -12
- data/lib/active_record/relation/query_methods.rb +130 -73
- data/lib/active_record/relation/spawn_methods.rb +10 -3
- data/lib/active_record/relation.rb +57 -25
- data/lib/active_record/result.rb +18 -7
- data/lib/active_record/sanitization.rb +12 -2
- data/lib/active_record/schema.rb +0 -1
- data/lib/active_record/schema_dumper.rb +59 -28
- data/lib/active_record/schema_migration.rb +5 -4
- data/lib/active_record/scoping/default.rb +6 -4
- data/lib/active_record/scoping/named.rb +4 -0
- data/lib/active_record/serializers/xml_serializer.rb +3 -7
- data/lib/active_record/statement_cache.rb +95 -10
- data/lib/active_record/store.rb +5 -5
- data/lib/active_record/tasks/database_tasks.rb +61 -8
- data/lib/active_record/tasks/mysql_database_tasks.rb +32 -17
- data/lib/active_record/tasks/postgresql_database_tasks.rb +20 -9
- data/lib/active_record/timestamp.rb +9 -7
- data/lib/active_record/transactions.rb +54 -28
- data/lib/active_record/type/big_integer.rb +13 -0
- data/lib/active_record/type/binary.rb +50 -0
- data/lib/active_record/type/boolean.rb +31 -0
- data/lib/active_record/type/date.rb +50 -0
- data/lib/active_record/type/date_time.rb +54 -0
- data/lib/active_record/type/decimal.rb +64 -0
- data/lib/active_record/type/decimal_without_scale.rb +11 -0
- data/lib/active_record/type/decorator.rb +14 -0
- data/lib/active_record/type/float.rb +19 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +23 -0
- data/lib/active_record/type/integer.rb +59 -0
- data/lib/active_record/type/mutable.rb +16 -0
- data/lib/active_record/type/numeric.rb +36 -0
- data/lib/active_record/type/serialized.rb +62 -0
- data/lib/active_record/type/string.rb +40 -0
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +26 -0
- data/lib/active_record/type/time_value.rb +38 -0
- data/lib/active_record/type/type_map.rb +64 -0
- data/lib/active_record/type/unsigned_integer.rb +15 -0
- data/lib/active_record/type/value.rb +110 -0
- data/lib/active_record/type.rb +23 -0
- data/lib/active_record/validations/associated.rb +5 -3
- data/lib/active_record/validations/presence.rb +5 -3
- data/lib/active_record/validations/uniqueness.rb +24 -20
- data/lib/active_record/validations.rb +25 -19
- data/lib/active_record.rb +5 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +8 -4
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb +1 -1
- metadata +66 -11
- data/lib/active_record/connection_adapters/postgresql/cast.rb +0 -168
@@ -29,9 +29,11 @@ module ActiveRecord
|
|
29
29
|
# Configuration options:
|
30
30
|
#
|
31
31
|
# * <tt>:message</tt> - A custom error message (default is: "is invalid").
|
32
|
-
# * <tt>:on</tt> - Specifies
|
33
|
-
# validation contexts by default (
|
34
|
-
#
|
32
|
+
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
33
|
+
# Runs in all validation contexts by default (nil). You can pass a symbol
|
34
|
+
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
35
|
+
# <tt>on: :custom_validation_context</tt> or
|
36
|
+
# <tt>on: [:create, :custom_validation_context]</tt>)
|
35
37
|
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
36
38
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
37
39
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
@@ -44,9 +44,11 @@ module ActiveRecord
|
|
44
44
|
#
|
45
45
|
# Configuration options:
|
46
46
|
# * <tt>:message</tt> - A custom error message (default is: "can't be blank").
|
47
|
-
# * <tt>:on</tt> - Specifies
|
48
|
-
# validation contexts by default (
|
49
|
-
#
|
47
|
+
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
48
|
+
# Runs in all validation contexts by default (nil). You can pass a symbol
|
49
|
+
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
50
|
+
# <tt>on: :custom_validation_context</tt> or
|
51
|
+
# <tt>on: [:create, :custom_validation_context]</tt>)
|
50
52
|
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
|
51
53
|
# the validation should occur (e.g. <tt>if: :allow_validation</tt>, or
|
52
54
|
# <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
|
@@ -13,14 +13,23 @@ module ActiveRecord
|
|
13
13
|
def validate_each(record, attribute, value)
|
14
14
|
finder_class = find_finder_class_for(record)
|
15
15
|
table = finder_class.arel_table
|
16
|
-
value = map_enum_attribute(finder_class,attribute,value)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
value = map_enum_attribute(finder_class, attribute, value)
|
17
|
+
|
18
|
+
begin
|
19
|
+
relation = build_relation(finder_class, table, attribute, value)
|
20
|
+
if record.persisted?
|
21
|
+
if finder_class.primary_key
|
22
|
+
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.id))
|
23
|
+
else
|
24
|
+
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
relation = scope_relation(record, table, relation)
|
28
|
+
relation = finder_class.unscoped.where(relation)
|
29
|
+
relation = relation.merge(options[:conditions]) if options[:conditions]
|
30
|
+
rescue RangeError
|
31
|
+
relation = finder_class.none
|
32
|
+
end
|
24
33
|
|
25
34
|
if relation.exists?
|
26
35
|
error_options = options.except(:case_sensitive, :scope, :conditions)
|
@@ -49,7 +58,7 @@ module ActiveRecord
|
|
49
58
|
def build_relation(klass, table, attribute, value) #:nodoc:
|
50
59
|
if reflection = klass._reflect_on_association(attribute)
|
51
60
|
attribute = reflection.foreign_key
|
52
|
-
value = value.attributes[reflection.
|
61
|
+
value = value.attributes[reflection.klass.primary_key] unless value.nil?
|
53
62
|
end
|
54
63
|
|
55
64
|
attribute_name = attribute.to_s
|
@@ -62,14 +71,15 @@ module ActiveRecord
|
|
62
71
|
|
63
72
|
column = klass.columns_hash[attribute_name]
|
64
73
|
value = klass.connection.type_cast(value, column)
|
65
|
-
|
74
|
+
if value.is_a?(String) && column.limit
|
75
|
+
value = value.to_s[0, column.limit]
|
76
|
+
end
|
66
77
|
|
67
78
|
if !options[:case_sensitive] && value && column.text?
|
68
79
|
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
69
80
|
klass.connection.case_insensitive_comparison(table, attribute, column, value)
|
70
81
|
else
|
71
|
-
|
72
|
-
table[attribute].eq(value)
|
82
|
+
klass.connection.case_sensitive_comparison(table, attribute, column, value)
|
73
83
|
end
|
74
84
|
end
|
75
85
|
|
@@ -79,7 +89,7 @@ module ActiveRecord
|
|
79
89
|
scope_value = record.send(reflection.foreign_key)
|
80
90
|
scope_item = reflection.foreign_key
|
81
91
|
else
|
82
|
-
scope_value = record.
|
92
|
+
scope_value = record._read_attribute(scope_item)
|
83
93
|
end
|
84
94
|
relation = relation.and(table[scope_item].eq(scope_value))
|
85
95
|
end
|
@@ -87,12 +97,6 @@ module ActiveRecord
|
|
87
97
|
relation
|
88
98
|
end
|
89
99
|
|
90
|
-
def deserialize_attribute(record, attribute, value)
|
91
|
-
coder = record.class.serialized_attributes[attribute.to_s]
|
92
|
-
value = coder.dump value if value && coder
|
93
|
-
value
|
94
|
-
end
|
95
|
-
|
96
100
|
def map_enum_attribute(klass, attribute, value)
|
97
101
|
mapping = klass.defined_enums[attribute.to_s]
|
98
102
|
value = mapping[value] if value && mapping
|
@@ -158,7 +162,7 @@ module ActiveRecord
|
|
158
162
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
159
163
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
160
164
|
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
|
161
|
-
# determine if the validation should
|
165
|
+
# determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
162
166
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
163
167
|
# method, proc or string should return or evaluate to a +true+ or +false+
|
164
168
|
# value.
|
@@ -5,13 +5,14 @@ module ActiveRecord
|
|
5
5
|
# +record+ method to retrieve the record which did not validate.
|
6
6
|
#
|
7
7
|
# begin
|
8
|
-
#
|
8
|
+
# complex_operation_that_internally_calls_save!
|
9
9
|
# rescue ActiveRecord::RecordInvalid => invalid
|
10
10
|
# puts invalid.record.errors
|
11
11
|
# end
|
12
12
|
class RecordInvalid < ActiveRecordError
|
13
|
-
attr_reader :record
|
14
|
-
|
13
|
+
attr_reader :record
|
14
|
+
|
15
|
+
def initialize(record)
|
15
16
|
@record = record
|
16
17
|
errors = @record.errors.full_messages.join(", ")
|
17
18
|
super(I18n.t(:"#{@record.class.i18n_scope}.errors.messages.record_invalid", :errors => errors, :default => :"errors.messages.record_invalid"))
|
@@ -29,21 +30,6 @@ module ActiveRecord
|
|
29
30
|
extend ActiveSupport::Concern
|
30
31
|
include ActiveModel::Validations
|
31
32
|
|
32
|
-
module ClassMethods
|
33
|
-
# Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
|
34
|
-
# so an exception is raised if the record is invalid.
|
35
|
-
def create!(attributes = nil, &block)
|
36
|
-
if attributes.is_a?(Array)
|
37
|
-
attributes.collect { |attr| create!(attr, &block) }
|
38
|
-
else
|
39
|
-
object = new(attributes)
|
40
|
-
yield(object) if block_given?
|
41
|
-
object.save!
|
42
|
-
object
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
33
|
# The validation process on save can be skipped by passing <tt>validate: false</tt>.
|
48
34
|
# The regular Base#save method is replaced with this when the validations
|
49
35
|
# module is mixed in, which it is by default.
|
@@ -54,12 +40,14 @@ module ActiveRecord
|
|
54
40
|
# Attempts to save the record just like Base#save but will raise a +RecordInvalid+
|
55
41
|
# exception instead of returning +false+ if the record is not valid.
|
56
42
|
def save!(options={})
|
57
|
-
perform_validations(options) ? super :
|
43
|
+
perform_validations(options) ? super : raise_record_invalid
|
58
44
|
end
|
59
45
|
|
60
46
|
# Runs all the validations within the specified context. Returns +true+ if
|
61
47
|
# no errors are found, +false+ otherwise.
|
62
48
|
#
|
49
|
+
# Aliased as validate.
|
50
|
+
#
|
63
51
|
# If the argument is +false+ (default is +nil+), the context is set to <tt>:create</tt> if
|
64
52
|
# <tt>new_record?</tt> is +true+, and to <tt>:update</tt> if it is not.
|
65
53
|
#
|
@@ -71,8 +59,26 @@ module ActiveRecord
|
|
71
59
|
errors.empty? && output
|
72
60
|
end
|
73
61
|
|
62
|
+
alias_method :validate, :valid?
|
63
|
+
|
64
|
+
# Runs all the validations within the specified context. Returns +true+ if
|
65
|
+
# no errors are found, raises +RecordInvalid+ otherwise.
|
66
|
+
#
|
67
|
+
# If the argument is +false+ (default is +nil+), the context is set to <tt>:create</tt> if
|
68
|
+
# <tt>new_record?</tt> is +true+, and to <tt>:update</tt> if it is not.
|
69
|
+
#
|
70
|
+
# Validations with no <tt>:on</tt> option will run no matter the context. Validations with
|
71
|
+
# some <tt>:on</tt> option will only run in the specified context.
|
72
|
+
def validate!(context = nil)
|
73
|
+
valid?(context) || raise_record_invalid
|
74
|
+
end
|
75
|
+
|
74
76
|
protected
|
75
77
|
|
78
|
+
def raise_record_invalid
|
79
|
+
raise(RecordInvalid.new(self))
|
80
|
+
end
|
81
|
+
|
76
82
|
def perform_validations(options={}) # :nodoc:
|
77
83
|
options[:validate] == false || valid?(options[:context])
|
78
84
|
end
|
data/lib/active_record.rb
CHANGED
@@ -27,10 +27,12 @@ require 'active_model'
|
|
27
27
|
require 'arel'
|
28
28
|
|
29
29
|
require 'active_record/version'
|
30
|
+
require 'active_record/attribute_set'
|
30
31
|
|
31
32
|
module ActiveRecord
|
32
33
|
extend ActiveSupport::Autoload
|
33
34
|
|
35
|
+
autoload :Attribute
|
34
36
|
autoload :Base
|
35
37
|
autoload :Callbacks
|
36
38
|
autoload :Core
|
@@ -50,6 +52,7 @@ module ActiveRecord
|
|
50
52
|
autoload :QueryCache
|
51
53
|
autoload :Querying
|
52
54
|
autoload :ReadonlyAttributes
|
55
|
+
autoload :RecordInvalid, 'active_record/validations'
|
53
56
|
autoload :Reflection
|
54
57
|
autoload :RuntimeRegistry
|
55
58
|
autoload :Sanitization
|
@@ -76,6 +79,8 @@ module ActiveRecord
|
|
76
79
|
autoload :AttributeMethods
|
77
80
|
autoload :AutosaveAssociation
|
78
81
|
|
82
|
+
autoload :LegacyYamlAdapter
|
83
|
+
|
79
84
|
autoload :Relation
|
80
85
|
autoload :AssociationRelation
|
81
86
|
autoload :NullRelation
|
@@ -23,16 +23,16 @@ module ActiveRecord
|
|
23
23
|
case file_name
|
24
24
|
when /^(add|remove)_.*_(?:to|from)_(.*)/
|
25
25
|
@migration_action = $1
|
26
|
-
@table_name = $2
|
26
|
+
@table_name = normalize_table_name($2)
|
27
27
|
when /join_table/
|
28
28
|
if attributes.length == 2
|
29
29
|
@migration_action = 'join'
|
30
|
-
@join_tables = attributes.map(&:plural_name)
|
30
|
+
@join_tables = pluralize_table_names? ? attributes.map(&:plural_name) : attributes.map(&:singular_name)
|
31
31
|
|
32
32
|
set_index_names
|
33
33
|
end
|
34
34
|
when /^create_(.+)/
|
35
|
-
@table_name = $1
|
35
|
+
@table_name = normalize_table_name($1)
|
36
36
|
@migration_template = "create_table_migration.rb"
|
37
37
|
end
|
38
38
|
end
|
@@ -55,12 +55,16 @@ module ActiveRecord
|
|
55
55
|
def attributes_with_index
|
56
56
|
attributes.select { |a| !a.reference? && a.has_index? }
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def validate_file_name!
|
60
60
|
unless file_name =~ /^[_a-z0-9]+$/
|
61
61
|
raise IllegalMigrationNameError.new(file_name)
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
def normalize_table_name(_table_name)
|
66
|
+
pluralize_table_names? ? _table_name.pluralize : _table_name.singularize
|
67
|
+
end
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
class <%= class_name %> < <%= parent_class_name.classify %>
|
3
3
|
<% attributes.select(&:reference?).each do |attribute| -%>
|
4
|
-
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
|
4
|
+
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
|
5
5
|
<% end -%>
|
6
6
|
<% if attributes.any?(&:password_digest?) -%>
|
7
7
|
has_secure_password
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: 4.2.11.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.
|
26
|
+
version: 4.2.11.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.
|
33
|
+
version: 4.2.11.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.
|
40
|
+
version: 4.2.11.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '6.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '6.0'
|
55
55
|
description: Databases on Rails. Build a persistent domain model by mapping database
|
56
56
|
tables to Ruby classes. Strong conventions for associations, validations, aggregations,
|
57
57
|
migrations, and testing come baked-in.
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/active_record/associations/builder/singular_association.rb
|
85
85
|
- lib/active_record/associations/collection_association.rb
|
86
86
|
- lib/active_record/associations/collection_proxy.rb
|
87
|
+
- lib/active_record/associations/foreign_association.rb
|
87
88
|
- lib/active_record/associations/has_many_association.rb
|
88
89
|
- lib/active_record/associations/has_many_through_association.rb
|
89
90
|
- lib/active_record/associations/has_one_association.rb
|
@@ -104,7 +105,9 @@ files:
|
|
104
105
|
- lib/active_record/associations/preloader/through_association.rb
|
105
106
|
- lib/active_record/associations/singular_association.rb
|
106
107
|
- lib/active_record/associations/through_association.rb
|
108
|
+
- lib/active_record/attribute.rb
|
107
109
|
- lib/active_record/attribute_assignment.rb
|
110
|
+
- lib/active_record/attribute_decorators.rb
|
108
111
|
- lib/active_record/attribute_methods.rb
|
109
112
|
- lib/active_record/attribute_methods/before_type_cast.rb
|
110
113
|
- lib/active_record/attribute_methods/dirty.rb
|
@@ -114,6 +117,9 @@ files:
|
|
114
117
|
- lib/active_record/attribute_methods/serialization.rb
|
115
118
|
- lib/active_record/attribute_methods/time_zone_conversion.rb
|
116
119
|
- lib/active_record/attribute_methods/write.rb
|
120
|
+
- lib/active_record/attribute_set.rb
|
121
|
+
- lib/active_record/attribute_set/builder.rb
|
122
|
+
- lib/active_record/attributes.rb
|
117
123
|
- lib/active_record/autosave_association.rb
|
118
124
|
- lib/active_record/base.rb
|
119
125
|
- lib/active_record/callbacks.rb
|
@@ -137,12 +143,39 @@ files:
|
|
137
143
|
- lib/active_record/connection_adapters/mysql2_adapter.rb
|
138
144
|
- lib/active_record/connection_adapters/mysql_adapter.rb
|
139
145
|
- lib/active_record/connection_adapters/postgresql/array_parser.rb
|
140
|
-
- lib/active_record/connection_adapters/postgresql/
|
146
|
+
- lib/active_record/connection_adapters/postgresql/column.rb
|
141
147
|
- lib/active_record/connection_adapters/postgresql/database_statements.rb
|
142
148
|
- lib/active_record/connection_adapters/postgresql/oid.rb
|
149
|
+
- lib/active_record/connection_adapters/postgresql/oid/array.rb
|
150
|
+
- lib/active_record/connection_adapters/postgresql/oid/bit.rb
|
151
|
+
- lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb
|
152
|
+
- lib/active_record/connection_adapters/postgresql/oid/bytea.rb
|
153
|
+
- lib/active_record/connection_adapters/postgresql/oid/cidr.rb
|
154
|
+
- lib/active_record/connection_adapters/postgresql/oid/date.rb
|
155
|
+
- lib/active_record/connection_adapters/postgresql/oid/date_time.rb
|
156
|
+
- lib/active_record/connection_adapters/postgresql/oid/decimal.rb
|
157
|
+
- lib/active_record/connection_adapters/postgresql/oid/enum.rb
|
158
|
+
- lib/active_record/connection_adapters/postgresql/oid/float.rb
|
159
|
+
- lib/active_record/connection_adapters/postgresql/oid/hstore.rb
|
160
|
+
- lib/active_record/connection_adapters/postgresql/oid/inet.rb
|
161
|
+
- lib/active_record/connection_adapters/postgresql/oid/infinity.rb
|
162
|
+
- lib/active_record/connection_adapters/postgresql/oid/integer.rb
|
163
|
+
- lib/active_record/connection_adapters/postgresql/oid/json.rb
|
164
|
+
- lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
|
165
|
+
- lib/active_record/connection_adapters/postgresql/oid/money.rb
|
166
|
+
- lib/active_record/connection_adapters/postgresql/oid/point.rb
|
167
|
+
- lib/active_record/connection_adapters/postgresql/oid/range.rb
|
168
|
+
- lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb
|
169
|
+
- lib/active_record/connection_adapters/postgresql/oid/time.rb
|
170
|
+
- lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
|
171
|
+
- lib/active_record/connection_adapters/postgresql/oid/uuid.rb
|
172
|
+
- lib/active_record/connection_adapters/postgresql/oid/vector.rb
|
173
|
+
- lib/active_record/connection_adapters/postgresql/oid/xml.rb
|
143
174
|
- lib/active_record/connection_adapters/postgresql/quoting.rb
|
144
175
|
- lib/active_record/connection_adapters/postgresql/referential_integrity.rb
|
176
|
+
- lib/active_record/connection_adapters/postgresql/schema_definitions.rb
|
145
177
|
- lib/active_record/connection_adapters/postgresql/schema_statements.rb
|
178
|
+
- lib/active_record/connection_adapters/postgresql/utils.rb
|
146
179
|
- lib/active_record/connection_adapters/postgresql_adapter.rb
|
147
180
|
- lib/active_record/connection_adapters/schema_cache.rb
|
148
181
|
- lib/active_record/connection_adapters/sqlite3_adapter.rb
|
@@ -161,6 +194,7 @@ files:
|
|
161
194
|
- lib/active_record/gem_version.rb
|
162
195
|
- lib/active_record/inheritance.rb
|
163
196
|
- lib/active_record/integration.rb
|
197
|
+
- lib/active_record/legacy_yaml_adapter.rb
|
164
198
|
- lib/active_record/locale/en.yml
|
165
199
|
- lib/active_record/locking/optimistic.rb
|
166
200
|
- lib/active_record/locking/pessimistic.rb
|
@@ -213,6 +247,28 @@ files:
|
|
213
247
|
- lib/active_record/timestamp.rb
|
214
248
|
- lib/active_record/transactions.rb
|
215
249
|
- lib/active_record/translation.rb
|
250
|
+
- lib/active_record/type.rb
|
251
|
+
- lib/active_record/type/big_integer.rb
|
252
|
+
- lib/active_record/type/binary.rb
|
253
|
+
- lib/active_record/type/boolean.rb
|
254
|
+
- lib/active_record/type/date.rb
|
255
|
+
- lib/active_record/type/date_time.rb
|
256
|
+
- lib/active_record/type/decimal.rb
|
257
|
+
- lib/active_record/type/decimal_without_scale.rb
|
258
|
+
- lib/active_record/type/decorator.rb
|
259
|
+
- lib/active_record/type/float.rb
|
260
|
+
- lib/active_record/type/hash_lookup_type_map.rb
|
261
|
+
- lib/active_record/type/integer.rb
|
262
|
+
- lib/active_record/type/mutable.rb
|
263
|
+
- lib/active_record/type/numeric.rb
|
264
|
+
- lib/active_record/type/serialized.rb
|
265
|
+
- lib/active_record/type/string.rb
|
266
|
+
- lib/active_record/type/text.rb
|
267
|
+
- lib/active_record/type/time.rb
|
268
|
+
- lib/active_record/type/time_value.rb
|
269
|
+
- lib/active_record/type/type_map.rb
|
270
|
+
- lib/active_record/type/unsigned_integer.rb
|
271
|
+
- lib/active_record/type/value.rb
|
216
272
|
- lib/active_record/validations.rb
|
217
273
|
- lib/active_record/validations/associated.rb
|
218
274
|
- lib/active_record/validations/presence.rb
|
@@ -247,8 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
303
|
- !ruby/object:Gem::Version
|
248
304
|
version: '0'
|
249
305
|
requirements: []
|
250
|
-
|
251
|
-
rubygems_version: 2.4.2
|
306
|
+
rubygems_version: 3.0.3
|
252
307
|
signing_key:
|
253
308
|
specification_version: 4
|
254
309
|
summary: Object-relational mapper framework (part of Rails).
|
@@ -1,168 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
class PostgreSQLColumn < Column
|
4
|
-
module Cast
|
5
|
-
def point_to_string(point)
|
6
|
-
"(#{point[0]},#{point[1]})"
|
7
|
-
end
|
8
|
-
|
9
|
-
def string_to_point(string)
|
10
|
-
if string[0] == '(' && string[-1] == ')'
|
11
|
-
string = string[1...-1]
|
12
|
-
end
|
13
|
-
string.split(',').map{ |v| Float(v) }
|
14
|
-
end
|
15
|
-
|
16
|
-
def string_to_time(string)
|
17
|
-
return string unless String === string
|
18
|
-
|
19
|
-
case string
|
20
|
-
when 'infinity'; Float::INFINITY
|
21
|
-
when '-infinity'; -Float::INFINITY
|
22
|
-
when / BC$/
|
23
|
-
super("-" + string.sub(/ BC$/, ""))
|
24
|
-
else
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def string_to_bit(value)
|
30
|
-
case value
|
31
|
-
when /^0x/i
|
32
|
-
value[2..-1].hex.to_s(2) # Hexadecimal notation
|
33
|
-
else
|
34
|
-
value # Bit-string notation
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def hstore_to_string(object, array_member = false)
|
39
|
-
if Hash === object
|
40
|
-
string = object.map { |k, v| "#{escape_hstore(k)}=>#{escape_hstore(v)}" }.join(',')
|
41
|
-
string = escape_hstore(string) if array_member
|
42
|
-
string
|
43
|
-
else
|
44
|
-
object
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def string_to_hstore(string)
|
49
|
-
if string.nil?
|
50
|
-
nil
|
51
|
-
elsif String === string
|
52
|
-
Hash[string.scan(HstorePair).map { |k, v|
|
53
|
-
v = v.upcase == 'NULL' ? nil : v.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
|
54
|
-
k = k.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
|
55
|
-
[k, v]
|
56
|
-
}]
|
57
|
-
else
|
58
|
-
string
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def json_to_string(object)
|
63
|
-
if Hash === object || Array === object
|
64
|
-
ActiveSupport::JSON.encode(object)
|
65
|
-
else
|
66
|
-
object
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def array_to_string(value, column, adapter)
|
71
|
-
casted_values = value.map do |val|
|
72
|
-
if String === val
|
73
|
-
if val == "NULL"
|
74
|
-
"\"#{val}\""
|
75
|
-
else
|
76
|
-
quote_and_escape(adapter.type_cast(val, column, true))
|
77
|
-
end
|
78
|
-
else
|
79
|
-
adapter.type_cast(val, column, true)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
"{#{casted_values.join(',')}}"
|
83
|
-
end
|
84
|
-
|
85
|
-
def range_to_string(object)
|
86
|
-
from = object.begin.respond_to?(:infinite?) && object.begin.infinite? ? '' : object.begin
|
87
|
-
to = object.end.respond_to?(:infinite?) && object.end.infinite? ? '' : object.end
|
88
|
-
"[#{from},#{to}#{object.exclude_end? ? ')' : ']'}"
|
89
|
-
end
|
90
|
-
|
91
|
-
def string_to_json(string)
|
92
|
-
if String === string
|
93
|
-
ActiveSupport::JSON.decode(string)
|
94
|
-
else
|
95
|
-
string
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def string_to_cidr(string)
|
100
|
-
if string.nil?
|
101
|
-
nil
|
102
|
-
elsif String === string
|
103
|
-
begin
|
104
|
-
IPAddr.new(string)
|
105
|
-
rescue ArgumentError
|
106
|
-
nil
|
107
|
-
end
|
108
|
-
else
|
109
|
-
string
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def cidr_to_string(object)
|
114
|
-
if IPAddr === object
|
115
|
-
"#{object.to_s}/#{object.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
|
116
|
-
else
|
117
|
-
object
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def string_to_array(string, oid)
|
122
|
-
parse_pg_array(string).map {|val| type_cast_array(oid, val)}
|
123
|
-
end
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
HstorePair = begin
|
128
|
-
quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"/
|
129
|
-
unquoted_string = /(?:\\.|[^\s,])[^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*/
|
130
|
-
/(#{quoted_string}|#{unquoted_string})\s*=>\s*(#{quoted_string}|#{unquoted_string})/
|
131
|
-
end
|
132
|
-
|
133
|
-
def escape_hstore(value)
|
134
|
-
if value.nil?
|
135
|
-
'NULL'
|
136
|
-
else
|
137
|
-
if value == ""
|
138
|
-
'""'
|
139
|
-
else
|
140
|
-
'"%s"' % value.to_s.gsub(/(["\\])/, '\\\\\1')
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
ARRAY_ESCAPE = "\\" * 2 * 2 # escape the backslash twice for PG arrays
|
146
|
-
|
147
|
-
def quote_and_escape(value)
|
148
|
-
case value
|
149
|
-
when "NULL", Numeric
|
150
|
-
value
|
151
|
-
else
|
152
|
-
value = value.gsub(/\\/, ARRAY_ESCAPE)
|
153
|
-
value.gsub!(/"/,"\\\"")
|
154
|
-
"\"#{value}\""
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def type_cast_array(oid, value)
|
159
|
-
if ::Array === value
|
160
|
-
value.map {|item| type_cast_array(oid, item)}
|
161
|
-
else
|
162
|
-
oid.type_cast value
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|