active_model_serializers 0.9.11 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/lib/active_model/serializer/association.rb +1 -3
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +30 -23
- data/test/fixtures/poro.rb +4 -3
- data/test/integration/generators/scaffold_controller_generator_test.rb +20 -20
- data/test/test_app.rb +4 -0
- data/test/tmp/app/serializers/account_serializer.rb +1 -2
- data/test/unit/active_model/array_serializer/serialization_test.rb +1 -1
- data/test/unit/active_model/default_serializer_test.rb +1 -1
- data/test/unit/active_model/serializer/url_helpers_test.rb +1 -0
- metadata +2 -12
- data/test/tmp/app/assets/javascripts/accounts.js +0 -2
- data/test/tmp/app/assets/stylesheets/accounts.css +0 -4
- data/test/tmp/app/controllers/accounts_controller.rb +0 -3
- data/test/tmp/app/helpers/accounts_helper.rb +0 -3
- data/test/tmp/config/routes.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8649ea9bfdefabb0215cc90a6a47a87d902573ecd0e2c73b6142c9cefe17825
|
4
|
+
data.tar.gz: 420e8afdc1ba7cbaaab42d7f8f36c3e10b702587cc7484e270428ded2eeccbdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 237f372c6dd5e73cb7d5f944d90918a23e6acf0f7aa137f0e2972a275445a549a6cf4ffd9e410386c611e89e1dc0137d5451c6d61702d6c6381e43a41e3434ac
|
7
|
+
data.tar.gz: 5d009500e9e616e7d1a7f83adaf7874022f1f039594983e923ef82d4b8f6b8f6268259404b097545a27512b149ec22c8e113a8c0bb51effbef3c0fdd728d7973
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
## 0.09.x
|
2
2
|
|
3
|
-
### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.
|
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)
|
9
|
+
|
10
|
+
### [v0.9.12 (2024-04-11)](https://github.com/rails-api/active_model_serializers/compare/v0.9.11...v0.9.12)
|
11
|
+
|
12
|
+
- Fix
|
13
|
+
- [#2468](https://github.com/rails-api/active_model_serializers/pull/2468) Fix bug introduced in v0.9.9. Revert "Allow serializer_for to accept String instead of just class objects". (@byroot)
|
14
|
+
- Perf
|
15
|
+
- [#2466](https://github.com/rails-api/active_model_serializers/pull/2466) Prefer `defined?` to `Object.constants.include?` (@byroot)
|
16
|
+
- [#2467](https://github.com/rails-api/active_model_serializers/pull/2467) Lazily compute possible serializer class names (@byroot)
|
17
|
+
- Chore
|
18
|
+
- [#2469](https://github.com/rails-api/active_model_serializers/pull/2469) Fix various warnings in the test suite (@byroot)
|
4
19
|
|
5
20
|
### [v0.9.11 (2024-04-09)](https://github.com/rails-api/active_model_serializers/compare/v0.9.10...v0.9.11)
|
6
21
|
|
@@ -9,9 +9,7 @@ module ActiveModel
|
|
9
9
|
class Association
|
10
10
|
def initialize(name, options={})
|
11
11
|
if options.has_key?(:include)
|
12
|
-
ActiveSupport::Deprecation.warn
|
13
|
-
** Notice: include was renamed to embed_in_root. **
|
14
|
-
WARN
|
12
|
+
ActiveSupport::Deprecation.warn("** Notice: include was renamed to embed_in_root. **")
|
15
13
|
end
|
16
14
|
|
17
15
|
@name = name.to_s
|
@@ -62,20 +62,19 @@ end
|
|
62
62
|
if resource.respond_to?(:serializer_class)
|
63
63
|
resource.serializer_class
|
64
64
|
elsif resource.respond_to?(:to_ary)
|
65
|
-
if
|
65
|
+
if defined?(::ArraySerializer)
|
66
66
|
::ArraySerializer
|
67
67
|
else
|
68
68
|
ArraySerializer
|
69
69
|
end
|
70
70
|
else
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
result.find { |serializer| !serializer.nil? }
|
71
|
+
each_possible_serializer(resource, options) do |klass_name|
|
72
|
+
serializer = Serializer.serializers_cache.fetch_or_store(klass_name) do
|
73
|
+
_const_get(klass_name)
|
74
|
+
end
|
75
|
+
return serializer unless serializer.nil?
|
76
|
+
end
|
77
|
+
nil
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
@@ -91,15 +90,27 @@ end
|
|
91
90
|
end
|
92
91
|
|
93
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"]
|
94
99
|
attrs.each do |attr|
|
95
100
|
striped_attr = strip_attribute attr
|
96
101
|
|
97
102
|
@_attributes << striped_attr
|
98
103
|
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
102
111
|
end
|
112
|
+
caller = caller_locations(1, 1).first
|
113
|
+
class_eval(source.join(";"), caller.path, caller.lineno - 1)
|
103
114
|
end
|
104
115
|
|
105
116
|
def has_one(*attrs)
|
@@ -124,22 +135,17 @@ end
|
|
124
135
|
attr
|
125
136
|
end
|
126
137
|
|
127
|
-
def
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
list << build_serializer_class(resource.class.name.demodulize, {})
|
138
|
+
def each_possible_serializer(resource, options)
|
139
|
+
yield build_serializer_class(resource, options)
|
140
|
+
yield build_serializer_class(resource, {})
|
141
|
+
yield build_serializer_class(resource.class.name.demodulize, {})
|
132
142
|
end
|
133
143
|
|
134
144
|
def build_serializer_class(resource, options)
|
135
145
|
klass_name = +""
|
136
146
|
klass_name << "#{options[:namespace]}::" if options[:namespace]
|
137
147
|
klass_name << options[:prefix].to_s.classify if options[:prefix]
|
138
|
-
|
139
|
-
klass_name << "#{resource}Serializer"
|
140
|
-
else
|
141
|
-
klass_name << "#{resource.class.name}Serializer"
|
142
|
-
end
|
148
|
+
klass_name << "#{resource.class.name}Serializer"
|
143
149
|
end
|
144
150
|
|
145
151
|
def associate(klass, *attrs)
|
@@ -169,7 +175,8 @@ end
|
|
169
175
|
@context = options[:context]
|
170
176
|
@namespace = options[:namespace]
|
171
177
|
end
|
172
|
-
attr_accessor :object, :scope, :root, :meta_key, :meta, :
|
178
|
+
attr_accessor :object, :scope, :root, :meta_key, :meta, :context, :polymorphic
|
179
|
+
attr_writer :key_format
|
173
180
|
|
174
181
|
def json_key
|
175
182
|
key = if root == true || root.nil?
|
data/test/fixtures/poro.rb
CHANGED
@@ -144,14 +144,14 @@ end
|
|
144
144
|
|
145
145
|
class SelfReferencingUserParentSerializer < ActiveModel::Serializer
|
146
146
|
attributes :name
|
147
|
-
has_one :type, serializer: TypeSerializer, embed: :ids,
|
147
|
+
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
|
148
148
|
end
|
149
149
|
|
150
150
|
class SelfReferencingUserSerializer < ActiveModel::Serializer
|
151
151
|
attributes :name
|
152
152
|
|
153
|
-
has_one :type, serializer: TypeSerializer, embed: :ids,
|
154
|
-
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids,
|
153
|
+
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
|
154
|
+
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, embed_in_root: true
|
155
155
|
end
|
156
156
|
|
157
157
|
class UserInfoSerializer < ActiveModel::Serializer
|
@@ -176,6 +176,7 @@ end
|
|
176
176
|
class PostSerializer < ActiveModel::Serializer
|
177
177
|
attributes :title, :body
|
178
178
|
|
179
|
+
alias_method :title, :title # silence method redefinition warning
|
179
180
|
def title
|
180
181
|
keyword = serialization_options[:highlight_keyword]
|
181
182
|
title = object.read_attribute_for_serialization(:title)
|
@@ -17,44 +17,44 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|
17
17
|
|
18
18
|
assert_file 'app/controllers/accounts_controller.rb' do |content|
|
19
19
|
assert_instance_method :index, content do |m|
|
20
|
-
assert_match
|
21
|
-
assert_match
|
22
|
-
assert_match
|
20
|
+
assert_match(/@accounts = Account\.all/, m)
|
21
|
+
assert_match(/format.html/, m)
|
22
|
+
assert_match(/format.json \{ render json: @accounts \}/, m)
|
23
23
|
end
|
24
24
|
|
25
25
|
assert_instance_method :show, content do |m|
|
26
|
-
assert_match
|
27
|
-
assert_match
|
26
|
+
assert_match(/format.html/, m)
|
27
|
+
assert_match(/format.json \{ render json: @account \}/, m)
|
28
28
|
end
|
29
29
|
|
30
30
|
assert_instance_method :new, content do |m|
|
31
|
-
assert_match
|
31
|
+
assert_match(/@account = Account\.new/, m)
|
32
32
|
end
|
33
33
|
|
34
34
|
assert_instance_method :edit, content do |m|
|
35
|
-
|
35
|
+
assert_predicate m, :blank?
|
36
36
|
end
|
37
37
|
|
38
38
|
assert_instance_method :create, content do |m|
|
39
|
-
assert_match
|
40
|
-
assert_match
|
41
|
-
assert_match
|
42
|
-
assert_match
|
43
|
-
assert_match
|
44
|
-
assert_match
|
39
|
+
assert_match(/@account = Account\.new\(account_params\)/, m)
|
40
|
+
assert_match(/@account\.save/, m)
|
41
|
+
assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully created\.' \}/, m)
|
42
|
+
assert_match(/format\.json \{ render json: @account, status: :created \}/, m)
|
43
|
+
assert_match(/format\.html \{ render action: 'new' \}/, m)
|
44
|
+
assert_match(/format\.json \{ render json: @account\.errors, status: :unprocessable_entity \}/, m)
|
45
45
|
end
|
46
46
|
|
47
47
|
assert_instance_method :update, content do |m|
|
48
|
-
assert_match
|
49
|
-
assert_match
|
50
|
-
assert_match
|
51
|
-
assert_match
|
48
|
+
assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully updated\.' \}/, m)
|
49
|
+
assert_match(/format\.json \{ head :no_content \}/, m)
|
50
|
+
assert_match(/format\.html \{ render action: 'edit' \}/, m)
|
51
|
+
assert_match(/format\.json \{ render json: @account.errors, status: :unprocessable_entity \}/, m)
|
52
52
|
end
|
53
53
|
|
54
54
|
assert_instance_method :destroy, content do |m|
|
55
|
-
assert_match
|
56
|
-
assert_match
|
57
|
-
assert_match
|
55
|
+
assert_match(/@account\.destroy/, m)
|
56
|
+
assert_match(/format\.html { redirect_to accounts_url \}/, m)
|
57
|
+
assert_match(/format\.json \{ head :no_content \}/, m)
|
58
58
|
end
|
59
59
|
|
60
60
|
assert_match(/def account_params/, content)
|
data/test/test_app.rb
CHANGED
@@ -49,7 +49,7 @@ module ActiveModel
|
|
49
49
|
def object.serializer_class; CustomSerializer; end
|
50
50
|
|
51
51
|
assert_equal CustomSerializer, Serializer.serializer_for(object)
|
52
|
-
|
52
|
+
assert_nil Serializer.serializer_for('Custom')
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -4,7 +4,7 @@ module ActiveModel
|
|
4
4
|
class DefaultSerializer
|
5
5
|
class Test < Minitest::Test
|
6
6
|
def test_serialize_objects
|
7
|
-
|
7
|
+
assert_nil(DefaultSerializer.new(nil).serializable_object)
|
8
8
|
assert_equal(1, DefaultSerializer.new(1).serializable_object)
|
9
9
|
assert_equal('hi', DefaultSerializer.new('hi').serializable_object)
|
10
10
|
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.
|
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-
|
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
|
data/test/tmp/config/routes.rb
DELETED