activemodel 7.0.4 → 6.1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +101 -103
  3. data/MIT-LICENSE +0 -1
  4. data/README.rdoc +3 -3
  5. data/lib/active_model/attribute.rb +0 -4
  6. data/lib/active_model/attribute_methods.rb +82 -67
  7. data/lib/active_model/attribute_set/builder.rb +10 -1
  8. data/lib/active_model/attribute_set.rb +1 -4
  9. data/lib/active_model/attributes.rb +12 -15
  10. data/lib/active_model/callbacks.rb +3 -3
  11. data/lib/active_model/conversion.rb +2 -2
  12. data/lib/active_model/dirty.rb +4 -5
  13. data/lib/active_model/error.rb +2 -2
  14. data/lib/active_model/errors.rb +248 -55
  15. data/lib/active_model/gem_version.rb +5 -5
  16. data/lib/active_model/locale/en.yml +0 -1
  17. data/lib/active_model/model.rb +59 -6
  18. data/lib/active_model/naming.rb +8 -15
  19. data/lib/active_model/secure_password.rb +2 -25
  20. data/lib/active_model/serialization.rb +2 -6
  21. data/lib/active_model/translation.rb +2 -2
  22. data/lib/active_model/type/date.rb +1 -1
  23. data/lib/active_model/type/helpers/numeric.rb +1 -9
  24. data/lib/active_model/type/helpers/time_value.rb +3 -3
  25. data/lib/active_model/type/integer.rb +1 -4
  26. data/lib/active_model/type/registry.rb +38 -8
  27. data/lib/active_model/type/time.rb +1 -1
  28. data/lib/active_model/type.rb +6 -6
  29. data/lib/active_model/validations/absence.rb +2 -2
  30. data/lib/active_model/validations/acceptance.rb +1 -1
  31. data/lib/active_model/validations/callbacks.rb +1 -1
  32. data/lib/active_model/validations/clusivity.rb +1 -1
  33. data/lib/active_model/validations/confirmation.rb +5 -5
  34. data/lib/active_model/validations/exclusion.rb +3 -3
  35. data/lib/active_model/validations/format.rb +1 -1
  36. data/lib/active_model/validations/inclusion.rb +3 -3
  37. data/lib/active_model/validations/length.rb +2 -2
  38. data/lib/active_model/validations/numericality.rb +22 -29
  39. data/lib/active_model/validations/presence.rb +1 -1
  40. data/lib/active_model/validations/validates.rb +3 -3
  41. data/lib/active_model/validations/with.rb +4 -4
  42. data/lib/active_model/validations.rb +12 -12
  43. data/lib/active_model/validator.rb +5 -5
  44. data/lib/active_model/version.rb +1 -1
  45. data/lib/active_model.rb +0 -1
  46. metadata +9 -12
  47. data/lib/active_model/api.rb +0 -99
  48. data/lib/active_model/validations/comparability.rb +0 -29
  49. data/lib/active_model/validations/comparison.rb +0 -82
@@ -32,7 +32,7 @@ module ActiveModel
32
32
  # person.errors.messages # => {first_name:["starts with z."]}
33
33
  #
34
34
  # Note that <tt>ActiveModel::Validations</tt> automatically adds an +errors+
35
- # method to your instances initialized with a new ActiveModel::Errors
35
+ # method to your instances initialized with a new <tt>ActiveModel::Errors</tt>
36
36
  # object, so there is no need for you to do this manually.
37
37
  module Validations
38
38
  extend ActiveSupport::Concern
@@ -73,14 +73,14 @@ module ActiveModel
73
73
  # <tt>on: [:create, :custom_validation_context]</tt>)
74
74
  # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
75
75
  # * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
76
- # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
76
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
77
77
  # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
78
78
  # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
79
79
  # proc or string should return or evaluate to a +true+ or +false+ value.
80
- # * <tt>:unless</tt> - Specifies a method, proc, or string to call to
80
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to
81
81
  # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
82
82
  # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
83
- # method, proc, or string should return or evaluate to a +true+ or +false+
83
+ # method, proc or string should return or evaluate to a +true+ or +false+
84
84
  # value.
85
85
  def validates_each(*attr_names, &block)
86
86
  validates_with BlockValidator, _merge_attributes(attr_names), &block
@@ -118,7 +118,7 @@ module ActiveModel
118
118
  # end
119
119
  # end
120
120
  #
121
- # Or with a block where +self+ points to the current record to be validated:
121
+ # Or with a block where self points to the current record to be validated:
122
122
  #
123
123
  # class Comment
124
124
  # include ActiveModel::Validations
@@ -137,14 +137,14 @@ module ActiveModel
137
137
  # or an array of symbols. (e.g. <tt>on: :create</tt> or
138
138
  # <tt>on: :custom_validation_context</tt> or
139
139
  # <tt>on: [:create, :custom_validation_context]</tt>)
140
- # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
140
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
141
141
  # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
142
142
  # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
143
143
  # proc or string should return or evaluate to a +true+ or +false+ value.
144
- # * <tt>:unless</tt> - Specifies a method, proc, or string to call to
144
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to
145
145
  # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
146
146
  # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
147
- # method, proc, or string should return or evaluate to a +true+ or +false+
147
+ # method, proc or string should return or evaluate to a +true+ or +false+
148
148
  # value.
149
149
  #
150
150
  # NOTE: Calling +validate+ multiple times on the same method will overwrite previous definitions.
@@ -152,7 +152,7 @@ module ActiveModel
152
152
  def validate(*args, &block)
153
153
  options = args.extract_options!
154
154
 
155
- if args.all?(Symbol)
155
+ if args.all? { |arg| arg.is_a?(Symbol) }
156
156
  options.each_key do |k|
157
157
  unless VALID_OPTIONS_FOR_VALIDATE.include?(k)
158
158
  raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{VALID_OPTIONS_FOR_VALIDATE.map(&:inspect).join(', ')}. Perhaps you meant to call `validates` instead of `validate`?")
@@ -241,7 +241,7 @@ module ActiveModel
241
241
  # class Person
242
242
  # include ActiveModel::Validations
243
243
  #
244
- # attr_accessor :name, :age
244
+ # attr_accessor :name , :age
245
245
  #
246
246
  # validates_presence_of :name
247
247
  # validates_inclusion_of :age, in: 0..99
@@ -272,7 +272,7 @@ module ActiveModel
272
272
  end
273
273
 
274
274
  # Copy validators on inheritance.
275
- def inherited(base) # :nodoc:
275
+ def inherited(base) #:nodoc:
276
276
  dup = _validators.dup
277
277
  base._validators = dup.each { |k, v| dup[k] = v.dup }
278
278
  super
@@ -280,7 +280,7 @@ module ActiveModel
280
280
  end
281
281
 
282
282
  # Clean the +Errors+ object if instance is duped.
283
- def initialize_dup(other) # :nodoc:
283
+ def initialize_dup(other) #:nodoc:
284
284
  @errors = nil
285
285
  super
286
286
  end
@@ -65,7 +65,7 @@ module ActiveModel
65
65
  # life cycle, and not on each validation run.
66
66
  #
67
67
  # The easiest way to add custom validators for validating individual attributes
68
- # is with the convenient ActiveModel::EachValidator.
68
+ # is with the convenient <tt>ActiveModel::EachValidator</tt>.
69
69
  #
70
70
  # class TitleValidator < ActiveModel::EachValidator
71
71
  # def validate_each(record, attribute, value)
@@ -74,7 +74,7 @@ module ActiveModel
74
74
  # end
75
75
  #
76
76
  # This can now be used in combination with the +validates+ method
77
- # (see ActiveModel::Validations::ClassMethods#validates for more on this).
77
+ # (see <tt>ActiveModel::Validations::ClassMethods.validates</tt> for more on this).
78
78
  #
79
79
  # class Person
80
80
  # include ActiveModel::Validations
@@ -126,10 +126,10 @@ module ActiveModel
126
126
 
127
127
  # +EachValidator+ is a validator which iterates through the attributes given
128
128
  # in the options hash invoking the <tt>validate_each</tt> method passing in the
129
- # record, attribute, and value.
129
+ # record, attribute and value.
130
130
  #
131
131
  # All \Active \Model validations are built on top of this validator.
132
- class EachValidator < Validator
132
+ class EachValidator < Validator #:nodoc:
133
133
  attr_reader :attributes
134
134
 
135
135
  # Returns a new validator instance. All options will be available via the
@@ -174,7 +174,7 @@ module ActiveModel
174
174
 
175
175
  # +BlockValidator+ is a special +EachValidator+ which receives a block on initialization
176
176
  # and call this block for each attribute being validated. +validates_each+ uses this validator.
177
- class BlockValidator < EachValidator # :nodoc:
177
+ class BlockValidator < EachValidator #:nodoc:
178
178
  def initialize(options, &block)
179
179
  @block = block
180
180
  super
@@ -3,7 +3,7 @@
3
3
  require_relative "gem_version"
4
4
 
5
5
  module ActiveModel
6
- # Returns the currently loaded version of \Active \Model as a <tt>Gem::Version</tt>.
6
+ # Returns the version of the currently loaded \Active \Model as a <tt>Gem::Version</tt>
7
7
  def self.version
8
8
  gem_version
9
9
  end
data/lib/active_model.rb CHANGED
@@ -30,7 +30,6 @@ require "active_model/version"
30
30
  module ActiveModel
31
31
  extend ActiveSupport::Autoload
32
32
 
33
- autoload :API
34
33
  autoload :Attribute
35
34
  autoload :Attributes
36
35
  autoload :AttributeAssignment
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.4
4
+ version: 6.1.7.1
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: 2022-09-09 00:00:00.000000000 Z
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.4
19
+ version: 6.1.7.1
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: 7.0.4
26
+ version: 6.1.7.1
27
27
  description: A toolkit for building modeling frameworks like Active Record. Rich support
28
28
  for attributes, callbacks, validations, serialization, internationalization, and
29
29
  testing.
@@ -36,7 +36,6 @@ files:
36
36
  - MIT-LICENSE
37
37
  - README.rdoc
38
38
  - lib/active_model.rb
39
- - lib/active_model/api.rb
40
39
  - lib/active_model/attribute.rb
41
40
  - lib/active_model/attribute/user_provided_default.rb
42
41
  - lib/active_model/attribute_assignment.rb
@@ -88,8 +87,6 @@ files:
88
87
  - lib/active_model/validations/acceptance.rb
89
88
  - lib/active_model/validations/callbacks.rb
90
89
  - lib/active_model/validations/clusivity.rb
91
- - lib/active_model/validations/comparability.rb
92
- - lib/active_model/validations/comparison.rb
93
90
  - lib/active_model/validations/confirmation.rb
94
91
  - lib/active_model/validations/exclusion.rb
95
92
  - lib/active_model/validations/format.rb
@@ -107,10 +104,10 @@ licenses:
107
104
  - MIT
108
105
  metadata:
109
106
  bug_tracker_uri: https://github.com/rails/rails/issues
110
- changelog_uri: https://github.com/rails/rails/blob/v7.0.4/activemodel/CHANGELOG.md
111
- documentation_uri: https://api.rubyonrails.org/v7.0.4/
107
+ changelog_uri: https://github.com/rails/rails/blob/v6.1.7.1/activemodel/CHANGELOG.md
108
+ documentation_uri: https://api.rubyonrails.org/v6.1.7.1/
112
109
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
113
- source_code_uri: https://github.com/rails/rails/tree/v7.0.4/activemodel
110
+ source_code_uri: https://github.com/rails/rails/tree/v6.1.7.1/activemodel
114
111
  rubygems_mfa_required: 'true'
115
112
  post_install_message:
116
113
  rdoc_options: []
@@ -120,14 +117,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
117
  requirements:
121
118
  - - ">="
122
119
  - !ruby/object:Gem::Version
123
- version: 2.7.0
120
+ version: 2.5.0
124
121
  required_rubygems_version: !ruby/object:Gem::Requirement
125
122
  requirements:
126
123
  - - ">="
127
124
  - !ruby/object:Gem::Version
128
125
  version: '0'
129
126
  requirements: []
130
- rubygems_version: 3.3.3
127
+ rubygems_version: 3.4.3
131
128
  signing_key:
132
129
  specification_version: 4
133
130
  summary: A toolkit for building modeling frameworks (part of Rails).
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveModel
4
- # == Active \Model \API
5
- #
6
- # Includes the required interface for an object to interact with
7
- # Action Pack and Action View, using different Active Model modules.
8
- # It includes model name introspections, conversions, translations, and
9
- # validations. Besides that, it allows you to initialize the object with a
10
- # hash of attributes, pretty much like Active Record does.
11
- #
12
- # A minimal implementation could be:
13
- #
14
- # class Person
15
- # include ActiveModel::API
16
- # attr_accessor :name, :age
17
- # end
18
- #
19
- # person = Person.new(name: 'bob', age: '18')
20
- # person.name # => "bob"
21
- # person.age # => "18"
22
- #
23
- # Note that, by default, <tt>ActiveModel::API</tt> implements <tt>persisted?</tt>
24
- # to return +false+, which is the most common case. You may want to override
25
- # it in your class to simulate a different scenario:
26
- #
27
- # class Person
28
- # include ActiveModel::API
29
- # attr_accessor :id, :name
30
- #
31
- # def persisted?
32
- # self.id.present?
33
- # end
34
- # end
35
- #
36
- # person = Person.new(id: 1, name: 'bob')
37
- # person.persisted? # => true
38
- #
39
- # Also, if for some reason you need to run code on <tt>initialize</tt>, make
40
- # sure you call +super+ if you want the attributes hash initialization to
41
- # happen.
42
- #
43
- # class Person
44
- # include ActiveModel::API
45
- # attr_accessor :id, :name, :omg
46
- #
47
- # def initialize(attributes={})
48
- # super
49
- # @omg ||= true
50
- # end
51
- # end
52
- #
53
- # person = Person.new(id: 1, name: 'bob')
54
- # person.omg # => true
55
- #
56
- # For more detailed information on other functionalities available, please
57
- # refer to the specific modules included in <tt>ActiveModel::API</tt>
58
- # (see below).
59
- module API
60
- extend ActiveSupport::Concern
61
- include ActiveModel::AttributeAssignment
62
- include ActiveModel::Validations
63
- include ActiveModel::Conversion
64
-
65
- included do
66
- extend ActiveModel::Naming
67
- extend ActiveModel::Translation
68
- end
69
-
70
- # Initializes a new model with the given +params+.
71
- #
72
- # class Person
73
- # include ActiveModel::API
74
- # attr_accessor :name, :age
75
- # end
76
- #
77
- # person = Person.new(name: 'bob', age: '18')
78
- # person.name # => "bob"
79
- # person.age # => "18"
80
- def initialize(attributes = {})
81
- assign_attributes(attributes) if attributes
82
-
83
- super()
84
- end
85
-
86
- # Indicates if the model is persisted. Default is +false+.
87
- #
88
- # class Person
89
- # include ActiveModel::API
90
- # attr_accessor :id, :name
91
- # end
92
- #
93
- # person = Person.new(id: 1, name: 'bob')
94
- # person.persisted? # => false
95
- def persisted?
96
- false
97
- end
98
- end
99
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveModel
4
- module Validations
5
- module Comparability # :nodoc:
6
- COMPARE_CHECKS = { greater_than: :>, greater_than_or_equal_to: :>=,
7
- equal_to: :==, less_than: :<, less_than_or_equal_to: :<=,
8
- other_than: :!= }.freeze
9
-
10
- def option_value(record, option_value)
11
- case option_value
12
- when Proc
13
- option_value.call(record)
14
- when Symbol
15
- record.send(option_value)
16
- else
17
- option_value
18
- end
19
- end
20
-
21
- def error_options(value, option_value)
22
- options.except(*COMPARE_CHECKS.keys).merge!(
23
- count: option_value,
24
- value: value
25
- )
26
- end
27
- end
28
- end
29
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model/validations/comparability"
4
-
5
- module ActiveModel
6
- module Validations
7
- class ComparisonValidator < EachValidator # :nodoc:
8
- include Comparability
9
-
10
- def check_validity!
11
- unless (options.keys & COMPARE_CHECKS.keys).any?
12
- raise ArgumentError, "Expected one of :greater_than, :greater_than_or_equal_to, "\
13
- ":equal_to, :less_than, :less_than_or_equal_to, or :other_than option to be supplied."
14
- end
15
- end
16
-
17
- def validate_each(record, attr_name, value)
18
- options.slice(*COMPARE_CHECKS.keys).each do |option, raw_option_value|
19
- option_value = option_value(record, raw_option_value)
20
-
21
- if value.nil? || value.blank?
22
- return record.errors.add(attr_name, :blank, **error_options(value, option_value))
23
- end
24
-
25
- unless value.public_send(COMPARE_CHECKS[option], option_value)
26
- record.errors.add(attr_name, option, **error_options(value, option_value))
27
- end
28
- rescue ArgumentError => e
29
- record.errors.add(attr_name, e.message)
30
- end
31
- end
32
- end
33
-
34
- module HelperMethods
35
- # Validates the value of a specified attribute fulfills all
36
- # defined comparisons with another value, proc, or attribute.
37
- #
38
- # class Person < ActiveRecord::Base
39
- # validates_comparison_of :value, greater_than: 'the sum of its parts'
40
- # end
41
- #
42
- # Configuration options:
43
- # * <tt>:message</tt> - A custom error message (default is: "failed comparison").
44
- # * <tt>:greater_than</tt> - Specifies the value must be greater than the
45
- # supplied value.
46
- # * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be
47
- # greater than or equal to the supplied value.
48
- # * <tt>:equal_to</tt> - Specifies the value must be equal to the supplied
49
- # value.
50
- # * <tt>:less_than</tt> - Specifies the value must be less than the
51
- # supplied value.
52
- # * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less
53
- # than or equal to the supplied value.
54
- # * <tt>:other_than</tt> - Specifies the value must not be equal to the
55
- # supplied value.
56
- #
57
- # There is also a list of default options supported by every validator:
58
- # +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+ .
59
- # See ActiveModel::Validations::ClassMethods#validates for more information.
60
- #
61
- # The validator requires at least one of the following checks to be supplied.
62
- # Each will accept a proc, value, or a symbol which corresponds to a method:
63
- #
64
- # * <tt>:greater_than</tt>
65
- # * <tt>:greater_than_or_equal_to</tt>
66
- # * <tt>:equal_to</tt>
67
- # * <tt>:less_than</tt>
68
- # * <tt>:less_than_or_equal_to</tt>
69
- # * <tt>:other_than</tt>
70
- #
71
- # For example:
72
- #
73
- # class Person < ActiveRecord::Base
74
- # validates_comparison_of :birth_date, less_than_or_equal_to: -> { Date.today }
75
- # validates_comparison_of :preferred_name, other_than: :given_name, allow_nil: true
76
- # end
77
- def validates_comparison_of(*attr_names)
78
- validates_with ComparisonValidator, _merge_attributes(attr_names)
79
- end
80
- end
81
- end
82
- end