activemodel 7.1.3.4 → 7.1.4

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: 62a8e27551c3779ec7676e6d2e0e66c13c2a8f95c88562722bfdcb8d9d319f2f
4
- data.tar.gz: 2cd6f1f9bcf63a13c2688fbc6854d1173f657bfecbfca5ef9a24bd06b5c61f32
3
+ metadata.gz: 7c65d57cfe07c87ab6784d35d6cad7b867be9b1af79dbd9f94952bc853f1bdb2
4
+ data.tar.gz: 7ed7f9189c0b5856f04f00cbad7b4b666c3a04ff00ecb97cb95aca385a8952b0
5
5
  SHA512:
6
- metadata.gz: 1e2132e134510005376a33192f81e408fdc3e5813f368c7c8a0ce2b00328d963c94970549219a7e9b2352136a8c223da5bb2e753e9cae9e43ce2b0f6304ad8df
7
- data.tar.gz: bb81aaefa19e40042623a008d8e4d0e062f35590f4150eabb6349dd0b394b3b0d58276b2acdf17137a09c4f25a97caf011069590ff09cebb43581a3d7549919b
6
+ metadata.gz: 8c3efab2ebac160a00422547aa31c996135971e742680e26d1ecb93fe96ad95f76ebc6fb52932f58d84a4ee51a888f2701eef1bfe9d70da54fef0cf8a77233e6
7
+ data.tar.gz: 66dc340915cd6ffeef7e0a504f7fbcafda2e9af0b728a6679bd23b9e2db8c57f18cf10b64c4b4b2228b62f602e92f16384def45b70ac5f232e78467c8e7b3ab0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Rails 7.1.4 (August 22, 2024) ##
2
+
3
+ * No changes.
4
+
5
+
1
6
  ## Rails 7.1.3.4 (June 04, 2024) ##
2
7
 
3
8
  * No changes.
@@ -215,10 +215,8 @@ module ActiveModel
215
215
  end
216
216
  end
217
217
 
218
- def generate_alias_attribute_methods(code_generator, new_name, old_name)
219
- attribute_method_patterns.each do |pattern|
220
- alias_attribute_method_definition(code_generator, pattern, new_name, old_name)
221
- end
218
+ def generate_alias_attribute_methods(code_generator, new_name, old_name) # :nodoc:
219
+ define_attribute_method(old_name, _owner: code_generator, as: new_name)
222
220
  end
223
221
 
224
222
  def alias_attribute_method_definition(code_generator, pattern, new_name, old_name) # :nodoc:
@@ -231,7 +229,7 @@ module ActiveModel
231
229
  mangled_name = "__temp__#{target_name.unpack1("h*")}"
232
230
  end
233
231
 
234
- code_generator.define_cached_method(method_name, as: mangled_name, namespace: :alias_attribute) do |batch|
232
+ code_generator.define_cached_method(mangled_name, as: method_name, namespace: :alias_attribute) do |batch|
235
233
  body = if CALL_COMPILABLE_REGEXP.match?(target_name)
236
234
  "self.#{target_name}(#{parameters || ''})"
237
235
  else
@@ -321,25 +319,44 @@ module ActiveModel
321
319
  # person.name = 'Bob'
322
320
  # person.name # => "Bob"
323
321
  # person.name_short? # => true
324
- def define_attribute_method(attr_name, _owner: generated_attribute_methods)
322
+ def define_attribute_method(attr_name, _owner: generated_attribute_methods, as: attr_name)
325
323
  ActiveSupport::CodeGenerator.batch(_owner, __FILE__, __LINE__) do |owner|
326
324
  attribute_method_patterns.each do |pattern|
327
- method_name = pattern.method_name(attr_name)
328
-
329
- unless instance_method_already_implemented?(method_name)
330
- generate_method = "define_method_#{pattern.proxy_target}"
331
-
332
- if respond_to?(generate_method, true)
333
- send(generate_method, attr_name.to_s, owner: owner)
334
- else
335
- define_proxy_call(owner, method_name, pattern.proxy_target, pattern.parameters, attr_name.to_s, namespace: :active_model_proxy)
336
- end
337
- end
325
+ define_attribute_method_pattern(pattern, attr_name, owner: owner, as: as)
338
326
  end
339
327
  attribute_method_patterns_cache.clear
340
328
  end
341
329
  end
342
330
 
331
+ def define_attribute_method_pattern(pattern, attr_name, owner:, as:, override: false) # :nodoc:
332
+ canonical_method_name = pattern.method_name(attr_name)
333
+ public_method_name = pattern.method_name(as)
334
+
335
+ # If defining a regular attribute method, we don't override methods that are explictly
336
+ # defined in parrent classes.
337
+ if instance_method_already_implemented?(public_method_name)
338
+ # However, for `alias_attribute`, we always define the method.
339
+ # We check for override second because `instance_method_already_implemented?`
340
+ # also check for dangerous methods.
341
+ return unless override
342
+ end
343
+
344
+ generate_method = "define_method_#{pattern.proxy_target}"
345
+ if respond_to?(generate_method, true)
346
+ send(generate_method, attr_name.to_s, owner: owner, as: as)
347
+ else
348
+ define_proxy_call(
349
+ owner,
350
+ canonical_method_name,
351
+ pattern.proxy_target,
352
+ pattern.parameters,
353
+ attr_name.to_s,
354
+ namespace: :active_model_proxy,
355
+ as: public_method_name,
356
+ )
357
+ end
358
+ end
359
+
343
360
  # Removes all the previously dynamically defined methods from the class, including alias attribute methods.
344
361
  #
345
362
  # class Person
@@ -418,7 +435,7 @@ module ActiveModel
418
435
  # Define a method `name` in `mod` that dispatches to `send`
419
436
  # using the given `extra` args. This falls back on `send`
420
437
  # if the called name cannot be compiled.
421
- def define_proxy_call(code_generator, name, proxy_target, parameters, *call_args, namespace:)
438
+ def define_proxy_call(code_generator, name, proxy_target, parameters, *call_args, namespace:, as: name)
422
439
  mangled_name = name
423
440
  unless NAME_COMPILABLE_REGEXP.match?(name)
424
441
  mangled_name = "__temp__#{name.unpack1("h*")}"
@@ -426,9 +443,9 @@ module ActiveModel
426
443
 
427
444
  call_args.map!(&:inspect)
428
445
  call_args << parameters if parameters
429
- namespace = :"#{namespace}_#{proxy_target}_#{call_args.join("_")}}"
446
+ namespace = :"#{namespace}_#{proxy_target}"
430
447
 
431
- code_generator.define_cached_method(name, as: mangled_name, namespace: namespace) do |batch|
448
+ code_generator.define_cached_method(mangled_name, as: as, namespace: namespace) do |batch|
432
449
  body = if CALL_COMPILABLE_REGEXP.match?(proxy_target)
433
450
  "self.#{proxy_target}(#{call_args.join(", ")})"
434
451
  else
@@ -76,11 +76,11 @@ module ActiveModel
76
76
  end
77
77
 
78
78
  private
79
- def define_method_attribute=(name, owner:)
79
+ def define_method_attribute=(canonical_name, owner:, as: canonical_name)
80
80
  ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method(
81
- owner, name, writer: true,
81
+ owner, canonical_name, writer: true,
82
82
  ) do |temp_method_name, attr_name_expr|
83
- owner.define_cached_method("#{name}=", as: temp_method_name, namespace: :active_model) do |batch|
83
+ owner.define_cached_method(temp_method_name, as: "#{as}=", namespace: :active_model) do |batch|
84
84
  batch <<
85
85
  "def #{temp_method_name}(value)" <<
86
86
  " _write_attribute(#{attr_name_expr}, value)" <<
@@ -9,8 +9,8 @@ module ActiveModel
9
9
  module VERSION
10
10
  MAJOR = 7
11
11
  MINOR = 1
12
- TINY = 3
13
- PRE = "4"
12
+ TINY = 4
13
+ PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
data/lib/active_model.rb CHANGED
@@ -28,7 +28,7 @@ require "active_support/rails"
28
28
  require "active_model/version"
29
29
  require "active_model/deprecator"
30
30
 
31
- # :include: activemodel/README.rdoc
31
+ # :include: ../README.rdoc
32
32
  module ActiveModel
33
33
  extend ActiveSupport::Autoload
34
34
 
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.1.3.4
4
+ version: 7.1.4
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-22 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.1.3.4
19
+ version: 7.1.4
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.1.3.4
26
+ version: 7.1.4
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.1.3.4/activemodel/CHANGELOG.md
116
- documentation_uri: https://api.rubyonrails.org/v7.1.3.4/
115
+ changelog_uri: https://github.com/rails/rails/blob/v7.1.4/activemodel/CHANGELOG.md
116
+ documentation_uri: https://api.rubyonrails.org/v7.1.4/
117
117
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
118
- source_code_uri: https://github.com/rails/rails/tree/v7.1.3.4/activemodel
118
+ source_code_uri: https://github.com/rails/rails/tree/v7.1.4/activemodel
119
119
  rubygems_mfa_required: 'true'
120
120
  post_install_message:
121
121
  rdoc_options: []
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  - !ruby/object:Gem::Version
133
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).