activemodel 8.0.0.beta1 → 8.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 906d52ef894a9f6b8fc0eb97488a653bcf0c0b141747cf7a7d5e8dcedb65e929
4
- data.tar.gz: '084df4c1c4a669a5d5c583bb3a579fdbe1be8f7f2bc4c24506797f9197250d3f'
3
+ metadata.gz: cff9ce182fe19b1ba44acb21c565c8527602855ad42582c68ca865c6c7808418
4
+ data.tar.gz: ac9f1b90cdad91c42d192ccd31fff45f96236a05dfab084a6846a1bba2881f31
5
5
  SHA512:
6
- metadata.gz: acdcc972d445a2d7576785d1b145d66f2a895a9e21e6b17acdc5ef78871e49aea0a49694d92efce03c030b82e69b176298ced1eb8244bdd836151dd9dfaa5068
7
- data.tar.gz: 918efc3fb79b912bfbff1661cfec5f822d86f2c33a135389de8f8bba150196c85411db87fb17470bccfea852ff3cda3c5c19bdc336d85238040f99ee0374138d
6
+ metadata.gz: f1cd9e0aabc319cfa3b73d3951470b2c31adedc2aafc11a5cd25a13ddaa7f346db103d6351009bd0f681184e8fbf840358df747b808e59e2857133bd6e372561
7
+ data.tar.gz: 917d12bda8d9f7f7f442897256fd046d27f29ca0f8a28aee17c68773cf48772f0142f30603af455f952ec1a308a20b4fc70367eba3dcabaa28cb1c24397eccef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## Rails 8.0.0.rc1 (October 19, 2024) ##
2
+
3
+ * Add `:except_on` option for validations. Grants the ability to _skip_ validations in specified contexts.
4
+
5
+ ```ruby
6
+ class User < ApplicationRecord
7
+ #...
8
+ validates :birthday, presence: { except_on: :admin }
9
+ #...
10
+ end
11
+
12
+ user = User.new(attributes except birthday)
13
+ user.save(context: :admin)
14
+ ```
15
+
16
+ *Drew Bragg*
17
+
1
18
  ## Rails 8.0.0.beta1 (September 26, 2024) ##
2
19
 
3
20
  * Make `ActiveModel::Serialization#read_attribute_for_serialization` public
@@ -71,7 +71,7 @@ module ActiveModel
71
71
  end
72
72
 
73
73
  def deep_dup
74
- AttributeSet.new(attributes.deep_dup)
74
+ AttributeSet.new(attributes.transform_values(&:deep_dup))
75
75
  end
76
76
 
77
77
  def initialize_dup(_)
@@ -3,7 +3,7 @@
3
3
  module ActiveModel
4
4
  # = Active \Model \Conversion
5
5
  #
6
- # Handles default conversions: to_model, to_key, to_param, and to_partial_path.
6
+ # Handles default conversions: #to_model, #to_key, #to_param, and #to_partial_path.
7
7
  #
8
8
  # Let's take for example this non-persisted object.
9
9
  #
@@ -247,12 +247,18 @@ module ActiveModel
247
247
 
248
248
  def initialize_dup(other) # :nodoc:
249
249
  super
250
- if self.class.respond_to?(:_default_attributes)
251
- @attributes = self.class._default_attributes.map do |attr|
252
- attr.with_value_from_user(@attributes.fetch_value(attr.name))
250
+ @mutations_from_database = nil
251
+ end
252
+
253
+ def init_attributes(other) # :nodoc:
254
+ attrs = super
255
+ if other.persisted? && self.class.respond_to?(:_default_attributes)
256
+ self.class._default_attributes.map do |attr|
257
+ attr.with_value_from_user(attrs.fetch_value(attr.name))
253
258
  end
259
+ else
260
+ attrs
254
261
  end
255
- @mutations_from_database = nil
256
262
  end
257
263
 
258
264
  def as_json(options = {}) # :nodoc:
@@ -10,7 +10,7 @@ module ActiveModel
10
10
  MAJOR = 8
11
11
  MINOR = 0
12
12
  TINY = 0
13
- PRE = "beta1"
13
+ PRE = "rc1"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -114,8 +114,8 @@ module ActiveModel
114
114
  false
115
115
  end
116
116
 
117
- def map(value) # :nodoc:
118
- yield value
117
+ def map(value, &) # :nodoc:
118
+ value
119
119
  end
120
120
 
121
121
  def ==(other)
@@ -78,7 +78,12 @@ module ActiveModel
78
78
  # or an array of symbols. (e.g. <tt>on: :create</tt> or
79
79
  # <tt>on: :custom_validation_context</tt> or
80
80
  # <tt>on: [:create, :custom_validation_context]</tt>)
81
- # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
81
+ # * <tt>:except_on</tt> - Specifies the contexts where this validation is not active.
82
+ # Runs in all validation contexts by default +nil+. You can pass a symbol
83
+ # or an array of symbols. (e.g. <tt>except: :create</tt> or
84
+ # <tt>except_on: :custom_validation_context</tt> or
85
+ # <tt>except_on: [:create, :custom_validation_context]</tt>)
86
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
82
87
  # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
83
88
  # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
84
89
  # proc or string should return or evaluate to a +true+ or +false+ value.
@@ -155,7 +160,7 @@ module ActiveModel
155
160
  # When creating custom validators, it might be useful to be able to specify
156
161
  # additional default keys. This can be done by overwriting this method.
157
162
  def _validates_default_keys
158
- [:if, :unless, :on, :allow_blank, :allow_nil, :strict]
163
+ [:if, :unless, :on, :allow_blank, :allow_nil, :strict, :except_on]
159
164
  end
160
165
 
161
166
  def _parse_validates_options(options)
@@ -69,6 +69,11 @@ module ActiveModel
69
69
  # or an array of symbols. (e.g. <tt>on: :create</tt> or
70
70
  # <tt>on: :custom_validation_context</tt> or
71
71
  # <tt>on: [:create, :custom_validation_context]</tt>)
72
+ # * <tt>:except_on</tt> - Specifies the contexts where this validation is not active.
73
+ # Runs in all validation contexts by default +nil+. You can pass a symbol
74
+ # or an array of symbols. (e.g. <tt>except: :create</tt> or
75
+ # <tt>except_on: :custom_validation_context</tt> or
76
+ # <tt>except_on: [:create, :custom_validation_context]</tt>)
72
77
  # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
73
78
  # * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
74
79
  # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
@@ -84,7 +89,7 @@ module ActiveModel
84
89
  validates_with BlockValidator, _merge_attributes(attr_names), &block
85
90
  end
86
91
 
87
- VALID_OPTIONS_FOR_VALIDATE = [:on, :if, :unless, :prepend].freeze # :nodoc:
92
+ VALID_OPTIONS_FOR_VALIDATE = [:on, :if, :unless, :prepend, :except_on].freeze # :nodoc:
88
93
 
89
94
  # Adds a validation method or block to the class. This is useful when
90
95
  # overriding the +validate+ instance method becomes too unwieldy and
@@ -135,7 +140,12 @@ module ActiveModel
135
140
  # or an array of symbols. (e.g. <tt>on: :create</tt> or
136
141
  # <tt>on: :custom_validation_context</tt> or
137
142
  # <tt>on: [:create, :custom_validation_context]</tt>)
138
- # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
143
+ # * <tt>:except_on</tt> - Specifies the contexts where this validation is not active.
144
+ # Runs in all validation contexts by default +nil+. You can pass a symbol
145
+ # or an array of symbols. (e.g. <tt>except: :create</tt> or
146
+ # <tt>except_on: :custom_validation_context</tt> or
147
+ # <tt>except_on: [:create, :custom_validation_context]</tt>)
148
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
139
149
  # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
140
150
  # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
141
151
  # proc or string should return or evaluate to a +true+ or +false+ value.
@@ -162,6 +172,15 @@ module ActiveModel
162
172
  options = options.merge(if: [predicate_for_validation_context(options[:on]), *options[:if]])
163
173
  end
164
174
 
175
+ if options.key?(:except_on)
176
+ options = options.dup
177
+ options[:except_on] = Array(options[:except_on])
178
+ options[:unless] = [
179
+ ->(o) { (options[:except_on] & Array(o.validation_context)).any? },
180
+ *options[:unless]
181
+ ]
182
+ end
183
+
165
184
  set_callback(:validate, *args, options, &block)
166
185
  end
167
186
 
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: 8.0.0.beta1
4
+ version: 8.0.0.rc1
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: 2024-09-26 00:00:00.000000000 Z
11
+ date: 2024-10-19 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: 8.0.0.beta1
19
+ version: 8.0.0.rc1
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: 8.0.0.beta1
26
+ version: 8.0.0.rc1
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.
@@ -112,10 +112,10 @@ licenses:
112
112
  - MIT
113
113
  metadata:
114
114
  bug_tracker_uri: https://github.com/rails/rails/issues
115
- changelog_uri: https://github.com/rails/rails/blob/v8.0.0.beta1/activemodel/CHANGELOG.md
116
- documentation_uri: https://api.rubyonrails.org/v8.0.0.beta1/
115
+ changelog_uri: https://github.com/rails/rails/blob/v8.0.0.rc1/activemodel/CHANGELOG.md
116
+ documentation_uri: https://api.rubyonrails.org/v8.0.0.rc1/
117
117
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
118
- source_code_uri: https://github.com/rails/rails/tree/v8.0.0.beta1/activemodel
118
+ source_code_uri: https://github.com/rails/rails/tree/v8.0.0.rc1/activemodel
119
119
  rubygems_mfa_required: 'true'
120
120
  post_install_message:
121
121
  rdoc_options: []