activemodel 7.2.0.beta2 → 7.2.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: fcba13dc67fffbbc777417b4e5778805208184f14923bf2ac225d682c8bd8e4f
4
- data.tar.gz: e5ca96e2d9bfe3e1c8ce506529524c79568a7bd1602bb25003c541a8ebb52f8e
3
+ metadata.gz: 4e4af947ba350cc2f26dbd4e5b56ddecb3b9d93dd54a99834713be23726c83d1
4
+ data.tar.gz: 6929a8bb5679a900bc99a032e35b39689783ebcdd761e40373217ab7b94ad54c
5
5
  SHA512:
6
- metadata.gz: 3c96c9b7ee0214df39556f148840fbde844b15e2ea757a75381cb21451e270b6d2c2e16786d3b3c560878346d2d4ad43be3d48c3bd80e7cf9c1858e19b427d6e
7
- data.tar.gz: 26dcd62bdaf43519f236efbdf8c8f44fe4f2ef9e64e68781431c559cb6095008f44824cf05d20bd24efe06c6696def2122d7ca4759d769358fe83871fd50deea
6
+ metadata.gz: d213f2746a84034813f0f0b7d8d0fb6e234d4675114a2111ed94681c40efc3ef32a53a5eb7a9bd6cfbf7d11887bf6c048404ee3e5fc7f746c51fe48ebb084923
7
+ data.tar.gz: 4f871ca04625b04cb48b30c48c683069f90ce31ef96cb554f6c2000785325105cc2241a8ae67ad0e24181a0feebcffb8188da7c85a58e68183dc949a3ea2f137
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## Rails 7.2.0.rc1 (August 06, 2024) ##
2
+
3
+ * No changes.
4
+
5
+
6
+ ## Rails 7.2.0.beta3 (July 11, 2024) ##
7
+
8
+ * No changes.
9
+
10
+
1
11
  ## Rails 7.2.0.beta2 (June 04, 2024) ##
2
12
 
3
13
  * No changes.
@@ -215,9 +215,7 @@ module ActiveModel
215
215
  end
216
216
 
217
217
  def generate_alias_attribute_methods(code_generator, new_name, old_name)
218
- attribute_method_patterns.each do |pattern|
219
- alias_attribute_method_definition(code_generator, pattern, new_name, old_name)
220
- end
218
+ define_attribute_method(old_name, _owner: code_generator, as: new_name)
221
219
  end
222
220
 
223
221
  def alias_attribute_method_definition(code_generator, pattern, new_name, old_name) # :nodoc:
@@ -305,25 +303,45 @@ module ActiveModel
305
303
  # person.name = 'Bob'
306
304
  # person.name # => "Bob"
307
305
  # person.name_short? # => true
308
- def define_attribute_method(attr_name, _owner: generated_attribute_methods)
306
+ def define_attribute_method(attr_name, _owner: generated_attribute_methods, as: attr_name)
309
307
  ActiveSupport::CodeGenerator.batch(_owner, __FILE__, __LINE__) do |owner|
310
308
  attribute_method_patterns.each do |pattern|
311
- method_name = pattern.method_name(attr_name)
312
-
313
- unless instance_method_already_implemented?(method_name)
314
- generate_method = "define_method_#{pattern.proxy_target}"
315
-
316
- if respond_to?(generate_method, true)
317
- send(generate_method, attr_name.to_s, owner: owner)
318
- else
319
- define_proxy_call(owner, method_name, pattern.proxy_target, pattern.parameters, attr_name.to_s, namespace: :active_model_proxy)
320
- end
321
- end
309
+ define_attribute_method_pattern(pattern, attr_name, owner: owner, as: as)
322
310
  end
323
311
  attribute_method_patterns_cache.clear
324
312
  end
325
313
  end
326
314
 
315
+ def define_attribute_method_pattern(pattern, attr_name, owner:, as:, override: false) # :nodoc:
316
+ canonical_method_name = pattern.method_name(attr_name)
317
+ public_method_name = pattern.method_name(as)
318
+
319
+ # If defining a regular attribute method, we don't override methods that are explictly
320
+ # defined in parrent classes.
321
+ if instance_method_already_implemented?(public_method_name)
322
+ # However, for `alias_attribute`, we always define the method.
323
+ # We check for override second because `instance_method_already_implemented?`
324
+ # also check for dangerous methods.
325
+ return unless override
326
+ end
327
+
328
+ generate_method = "define_method_#{pattern.proxy_target}"
329
+
330
+ if respond_to?(generate_method, true)
331
+ send(generate_method, attr_name.to_s, owner: owner, as: as)
332
+ else
333
+ define_proxy_call(
334
+ owner,
335
+ canonical_method_name,
336
+ pattern.proxy_target,
337
+ pattern.parameters,
338
+ attr_name.to_s,
339
+ namespace: :active_model_proxy,
340
+ as: public_method_name
341
+ )
342
+ end
343
+ end
344
+
327
345
  # Removes all the previously dynamically defined methods from the class, including alias attribute methods.
328
346
  #
329
347
  # class Person
@@ -404,14 +422,19 @@ module ActiveModel
404
422
  # Define a method `name` in `mod` that dispatches to `send`
405
423
  # using the given `extra` args. This falls back on `send`
406
424
  # if the called name cannot be compiled.
407
- def define_proxy_call(code_generator, name, proxy_target, parameters, *call_args, namespace:)
425
+ def define_proxy_call(code_generator, name, proxy_target, parameters, *call_args, namespace:, as: name)
408
426
  mangled_name = build_mangled_name(name)
409
427
 
410
428
  call_args.map!(&:inspect)
411
429
  call_args << parameters if parameters
412
- namespace = :"#{namespace}_#{proxy_target}_#{call_args.join("_")}}"
413
430
 
414
- define_call(code_generator, name, proxy_target, mangled_name, parameters, call_args, namespace: namespace)
431
+ # We have to use a different namespace for every target method, because
432
+ # if someone defines an attribute that look like an attribute method we could clash, e.g.
433
+ # attribute :title_was
434
+ # attribute :title
435
+ namespace = :"#{namespace}_#{proxy_target}"
436
+
437
+ define_call(code_generator, name, proxy_target, mangled_name, parameters, call_args, namespace: namespace, as: as)
415
438
  end
416
439
 
417
440
  def build_mangled_name(name)
@@ -424,8 +447,8 @@ module ActiveModel
424
447
  mangled_name
425
448
  end
426
449
 
427
- def define_call(code_generator, name, target_name, mangled_name, parameters, call_args, namespace:)
428
- code_generator.define_cached_method(name, as: mangled_name, namespace: namespace) do |batch|
450
+ def define_call(code_generator, name, target_name, mangled_name, parameters, call_args, namespace:, as:)
451
+ code_generator.define_cached_method(mangled_name, as: as, namespace: namespace) do |batch|
429
452
  body = if CALL_COMPILABLE_REGEXP.match?(target_name)
430
453
  "self.#{target_name}(#{call_args.join(", ")})"
431
454
  else
@@ -89,11 +89,11 @@ module ActiveModel
89
89
 
90
90
  ##
91
91
  private
92
- def define_method_attribute=(name, owner:)
92
+ def define_method_attribute=(canonical_name, owner:, as: canonical_name)
93
93
  ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method(
94
- owner, name, writer: true,
94
+ owner, canonical_name, writer: true,
95
95
  ) do |temp_method_name, attr_name_expr|
96
- owner.define_cached_method("#{name}=", as: temp_method_name, namespace: :active_model) do |batch|
96
+ owner.define_cached_method(temp_method_name, as: "#{as}=", namespace: :active_model) do |batch|
97
97
  batch <<
98
98
  "def #{temp_method_name}(value)" <<
99
99
  " _write_attribute(#{attr_name_expr}, value)" <<
@@ -10,7 +10,7 @@ module ActiveModel
10
10
  MAJOR = 7
11
11
  MINOR = 2
12
12
  TINY = 0
13
- PRE = "beta2"
13
+ PRE = "rc1"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -70,18 +70,33 @@ module ActiveModel
70
70
  /x
71
71
 
72
72
  if RUBY_VERSION >= "3.2"
73
- def fast_string_to_time(string)
74
- return unless ISO_DATETIME.match?(string)
75
-
76
- if is_utc?
77
- # XXX: Wrapping the Time object with Time.at because Time.new with `in:` in Ruby 3.2.0 used to return an invalid Time object
78
- # see: https://bugs.ruby-lang.org/issues/19292
79
- ::Time.at(::Time.new(string, in: "UTC"))
80
- else
81
- ::Time.new(string)
73
+ if Time.new(2000, 1, 1, 0, 0, 0, "-00:00").yday != 1 # Early 3.2.x had a bug
74
+ # BUG: Wrapping the Time object with Time.at because Time.new with `in:` in Ruby 3.2.0
75
+ # used to return an invalid Time object
76
+ # see: https://bugs.ruby-lang.org/issues/19292
77
+ def fast_string_to_time(string)
78
+ return unless string.include?("-") # Time.new("1234") # => 1234-01-01 00:00:00
79
+
80
+ if is_utc?
81
+ ::Time.at(::Time.new(string, in: "UTC"))
82
+ else
83
+ ::Time.new(string)
84
+ end
85
+ rescue ArgumentError
86
+ nil
87
+ end
88
+ else
89
+ def fast_string_to_time(string)
90
+ return unless string.include?("-") # Time.new("1234") # => 1234-01-01 00:00:00
91
+
92
+ if is_utc?
93
+ ::Time.new(string, in: "UTC")
94
+ else
95
+ ::Time.new(string)
96
+ end
97
+ rescue ArgumentError
98
+ nil
82
99
  end
83
- rescue ArgumentError
84
- nil
85
100
  end
86
101
  else
87
102
  def fast_string_to_time(string)
@@ -7,7 +7,11 @@ module ActiveModel
7
7
  module Helpers # :nodoc: all
8
8
  module Timezone
9
9
  def is_utc?
10
- ::Time.zone_default.nil? || ::Time.zone_default.match?("UTC")
10
+ if default = ::Time.zone_default
11
+ default.name == "UTC"
12
+ else
13
+ true
14
+ end
11
15
  end
12
16
 
13
17
  def default_timezone
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.2.0.beta2
4
+ version: 7.2.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-06-04 00:00:00.000000000 Z
11
+ date: 2024-08-06 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.2.0.beta2
19
+ version: 7.2.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: 7.2.0.beta2
26
+ version: 7.2.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/v7.2.0.beta2/activemodel/CHANGELOG.md
116
- documentation_uri: https://api.rubyonrails.org/v7.2.0.beta2/
115
+ changelog_uri: https://github.com/rails/rails/blob/v7.2.0.rc1/activemodel/CHANGELOG.md
116
+ documentation_uri: https://api.rubyonrails.org/v7.2.0.rc1/
117
117
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
118
- source_code_uri: https://github.com/rails/rails/tree/v7.2.0.beta2/activemodel
118
+ source_code_uri: https://github.com/rails/rails/tree/v7.2.0.rc1/activemodel
119
119
  rubygems_mfa_required: 'true'
120
120
  post_install_message:
121
121
  rdoc_options: []
@@ -128,11 +128,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  version: 3.1.0
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">"
131
+ - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 1.3.1
133
+ version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.3.27
135
+ rubygems_version: 3.5.11
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: A toolkit for building modeling frameworks (part of Rails).