active_model_serializers 0.9.12 → 0.9.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61778c5b2b91da210dcc01075ef454249315c36600f82bea6996ed3290560003
4
- data.tar.gz: 75e07b2aaf633ea4c5b785ea9d95a23bf9a240e8ee232c80a2c2a8bc9bca4666
3
+ metadata.gz: a8649ea9bfdefabb0215cc90a6a47a87d902573ecd0e2c73b6142c9cefe17825
4
+ data.tar.gz: 420e8afdc1ba7cbaaab42d7f8f36c3e10b702587cc7484e270428ded2eeccbdd
5
5
  SHA512:
6
- metadata.gz: dd16f19a2585c7fb2fdb4b54990eb71e306def01fc6757d42c19b26820f43d3afb82d28c44efd6c228bffcac7a84324277e9d17facaa22935bf8f3a1cf4ee588
7
- data.tar.gz: 06c780dffd320606869b1e377e08fdbc2b83f7ec2726ea100d3004e9ad7098f89d254ffb2b1b62477a08b0e6898b1a40ae0466bf137296559e3736c19ab7a760
6
+ metadata.gz: 237f372c6dd5e73cb7d5f944d90918a23e6acf0f7aa137f0e2972a275445a549a6cf4ffd9e410386c611e89e1dc0137d5451c6d61702d6c6381e43a41e3434ac
7
+ data.tar.gz: 5d009500e9e616e7d1a7f83adaf7874022f1f039594983e923ef82d4b8f6b8f6268259404b097545a27512b149ec22c8e113a8c0bb51effbef3c0fdd728d7973
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  ## 0.09.x
2
2
 
3
- ### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.12...0-9-stable)
3
+ ### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.13...0-9-stable)
4
+
5
+ ### [v0.9.13 (2024-09-17)](https://github.com/rails-api/active_model_serializers/compare/v0.9.12...v0.9.13)
6
+
7
+ - Perf
8
+ - [#2471](https://github.com/rails-api/active_model_serializers/pull/2471) Generate better attribute accessors, that also don't trigger warnings when redefined. (@byroot)
4
9
 
5
10
  ### [v0.9.12 (2024-04-11)](https://github.com/rails-api/active_model_serializers/compare/v0.9.11...v0.9.12)
6
11
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveModel
4
4
  class Serializer
5
- VERSION = '0.9.12'
5
+ VERSION = '0.9.13'
6
6
  end
7
7
  end
@@ -90,15 +90,27 @@ end
90
90
  end
91
91
 
92
92
  def attributes(*attrs)
93
+ # Use `class_eval` rather than `define_method` for faster access
94
+ # and avoid retaining objects in the closure.
95
+ # Batch all methods in a single `class_eval` for efficiceny,
96
+ # and define all methods on the same line so the eventual backtrace
97
+ # properly maps to the `attributes` call.
98
+ source = ["# frozen_string_literal: true\n"]
93
99
  attrs.each do |attr|
94
100
  striped_attr = strip_attribute attr
95
101
 
96
102
  @_attributes << striped_attr
97
103
 
98
- define_method striped_attr do
99
- object.read_attribute_for_serialization attr
100
- end unless method_defined?(attr)
104
+ unless method_defined?(attr)
105
+ source <<
106
+ "def #{striped_attr}" <<
107
+ "object.read_attribute_for_serialization(#{attr.inspect})" <<
108
+ "end" <<
109
+ "alias_method :#{striped_attr}, :#{striped_attr}" # suppress method redefinition warning
110
+ end
101
111
  end
112
+ caller = caller_locations(1, 1).first
113
+ class_eval(source.join(";"), caller.path, caller.lineno - 1)
102
114
  end
103
115
 
104
116
  def has_one(*attrs)
@@ -1,4 +1,3 @@
1
- # frozen_string_literal: true
2
- class AccountSerializer < ActiveModel::Serializer
1
+ class AccountSerializer < MySerializer
3
2
  attributes :id
4
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-04-11 00:00:00.000000000 Z
13
+ date: 2024-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -115,12 +115,7 @@ files:
115
115
  - test/integration/generators/serializer_generator_test.rb
116
116
  - test/test_app.rb
117
117
  - test/test_helper.rb
118
- - test/tmp/app/assets/javascripts/accounts.js
119
- - test/tmp/app/assets/stylesheets/accounts.css
120
- - test/tmp/app/controllers/accounts_controller.rb
121
- - test/tmp/app/helpers/accounts_helper.rb
122
118
  - test/tmp/app/serializers/account_serializer.rb
123
- - test/tmp/config/routes.rb
124
119
  - test/unit/active_model/array_serializer/except_test.rb
125
120
  - test/unit/active_model/array_serializer/key_format_test.rb
126
121
  - test/unit/active_model/array_serializer/meta_test.rb
@@ -198,12 +193,7 @@ test_files:
198
193
  - test/integration/generators/serializer_generator_test.rb
199
194
  - test/test_app.rb
200
195
  - test/test_helper.rb
201
- - test/tmp/app/assets/javascripts/accounts.js
202
- - test/tmp/app/assets/stylesheets/accounts.css
203
- - test/tmp/app/controllers/accounts_controller.rb
204
- - test/tmp/app/helpers/accounts_helper.rb
205
196
  - test/tmp/app/serializers/account_serializer.rb
206
- - test/tmp/config/routes.rb
207
197
  - test/unit/active_model/array_serializer/except_test.rb
208
198
  - test/unit/active_model/array_serializer/key_format_test.rb
209
199
  - test/unit/active_model/array_serializer/meta_test.rb
@@ -1,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.
@@ -1,4 +0,0 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
- class AccountsController < ApplicationController
3
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
- module AccountsHelper
3
- end
@@ -1,2 +0,0 @@
1
- # frozen_string_literal: true
2
- Rails.application.routes.draw {}