active_model_serializers 0.8.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +122 -5
- data/CONTRIBUTING.md +20 -0
- data/DESIGN.textile +4 -4
- data/{MIT-LICENSE.txt → MIT-LICENSE} +0 -0
- data/README.md +396 -95
- data/lib/action_controller/serialization.rb +50 -12
- data/lib/action_controller/serialization_test_case.rb +79 -0
- data/lib/active_model/array_serializer.rb +47 -78
- data/lib/active_model/default_serializer.rb +32 -0
- data/lib/active_model/serializable/utils.rb +16 -0
- data/lib/active_model/serializable.rb +62 -0
- data/lib/active_model/serializer/association/has_many.rb +39 -0
- data/lib/active_model/serializer/association/has_one.rb +25 -0
- data/lib/active_model/serializer/association.rb +58 -0
- data/lib/active_model/serializer/config.rb +31 -0
- data/lib/active_model/serializer/generators/resource_override.rb +13 -0
- data/lib/{generators → active_model/serializer/generators}/serializer/USAGE +0 -0
- data/lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb +14 -0
- data/lib/active_model/serializer/generators/serializer/serializer_generator.rb +37 -0
- data/lib/active_model/serializer/generators/serializer/templates/controller.rb +93 -0
- data/lib/active_model/serializer/generators/serializer/templates/serializer.rb +8 -0
- data/lib/active_model/serializer/railtie.rb +18 -0
- data/lib/active_model/{serializers → serializer}/version.rb +1 -1
- data/lib/active_model/serializer.rb +214 -423
- data/lib/active_model/serializer_support.rb +5 -0
- data/lib/active_model_serializers/mime_types.rb +14 -0
- data/lib/active_model_serializers.rb +12 -87
- data/test/fixtures/active_record.rb +96 -0
- data/test/fixtures/poro.rb +187 -0
- data/test/fixtures/template.html.erb +1 -0
- data/test/integration/action_controller/namespaced_serialization_test.rb +105 -0
- data/test/integration/action_controller/serialization_test.rb +287 -0
- data/test/integration/action_controller/serialization_test_case_test.rb +71 -0
- data/test/integration/active_record/active_record_test.rb +94 -0
- data/test/integration/generators/resource_generator_test.rb +26 -0
- data/test/integration/generators/scaffold_controller_generator_test.rb +64 -0
- data/test/integration/generators/serializer_generator_test.rb +41 -0
- data/test/test_app.rb +14 -0
- data/test/test_helper.rb +10 -18
- data/test/unit/active_model/array_serializer/except_test.rb +18 -0
- data/test/unit/active_model/array_serializer/key_format_test.rb +18 -0
- data/test/unit/active_model/array_serializer/meta_test.rb +53 -0
- data/test/unit/active_model/array_serializer/only_test.rb +18 -0
- data/test/unit/active_model/array_serializer/options_test.rb +16 -0
- data/test/unit/active_model/array_serializer/root_test.rb +102 -0
- data/test/unit/active_model/array_serializer/scope_test.rb +24 -0
- data/test/unit/active_model/array_serializer/serialization_test.rb +216 -0
- data/test/unit/active_model/default_serializer_test.rb +13 -0
- data/test/unit/active_model/serializer/associations/build_serializer_test.rb +36 -0
- data/test/unit/active_model/serializer/associations_test.rb +19 -0
- data/test/unit/active_model/serializer/attributes_test.rb +57 -0
- data/test/unit/active_model/serializer/config_test.rb +91 -0
- data/test/unit/active_model/serializer/filter_test.rb +69 -0
- data/test/unit/active_model/serializer/has_many_polymorphic_test.rb +189 -0
- data/test/unit/active_model/serializer/has_many_test.rb +265 -0
- data/test/unit/active_model/serializer/has_one_and_has_many_test.rb +27 -0
- data/test/unit/active_model/serializer/has_one_polymorphic_test.rb +196 -0
- data/test/unit/active_model/serializer/has_one_test.rb +253 -0
- data/test/unit/active_model/serializer/key_format_test.rb +25 -0
- data/test/unit/active_model/serializer/meta_test.rb +39 -0
- data/test/unit/active_model/serializer/options_test.rb +42 -0
- data/test/unit/active_model/serializer/root_test.rb +117 -0
- data/test/unit/active_model/serializer/scope_test.rb +49 -0
- data/test/unit/active_model/serializer/url_helpers_test.rb +35 -0
- metadata +107 -64
- data/.gitignore +0 -18
- data/.travis.yml +0 -28
- data/Gemfile +0 -4
- data/Gemfile.edge +0 -9
- data/Rakefile +0 -18
- data/active_model_serializers.gemspec +0 -24
- data/bench/perf.rb +0 -43
- data/cruft.md +0 -19
- data/lib/active_model/serializer/associations.rb +0 -233
- data/lib/active_record/serializer_override.rb +0 -16
- data/lib/generators/resource_override.rb +0 -13
- data/lib/generators/serializer/serializer_generator.rb +0 -42
- data/lib/generators/serializer/templates/serializer.rb +0 -19
- data/test/array_serializer_test.rb +0 -75
- data/test/association_test.rb +0 -592
- data/test/caching_test.rb +0 -96
- data/test/generators_test.rb +0 -85
- data/test/no_serialization_scope_test.rb +0 -34
- data/test/serialization_scope_name_test.rb +0 -67
- data/test/serialization_test.rb +0 -392
- data/test/serializer_support_test.rb +0 -51
- data/test/serializer_test.rb +0 -1465
- data/test/test_fakes.rb +0 -217
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class ScopeTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@serializer = ProfileSerializer.new(nil, scope: current_user)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_scope
|
11
|
+
assert_equal('user', @serializer.scope)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
'user'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class NestedScopeTest < Minitest::Test
|
22
|
+
def setup
|
23
|
+
@association = UserSerializer._associations[:profile]
|
24
|
+
@old_association = @association.dup
|
25
|
+
@user = User.new({ name: 'Name 1', email: 'mail@server.com', gender: 'M' })
|
26
|
+
@user_serializer = UserSerializer.new(@user, scope: 'user')
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
UserSerializer._associations[:profile] = @old_association
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_scope_passed_through
|
34
|
+
@association.serializer_from_options = Class.new(Serializer) do
|
35
|
+
def name
|
36
|
+
scope
|
37
|
+
end
|
38
|
+
|
39
|
+
attributes :name
|
40
|
+
end
|
41
|
+
|
42
|
+
assert_equal({
|
43
|
+
name: 'Name 1', email: 'mail@server.com', profile: { name: 'user' }
|
44
|
+
}, @user_serializer.serializable_hash)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class UrlHelpersTest < Minitest::Test
|
6
|
+
include Rails.application.routes.url_helpers
|
7
|
+
|
8
|
+
def setup
|
9
|
+
Object.const_set 'UserController', Class.new(ActionController::Base) do
|
10
|
+
def show
|
11
|
+
render text: 'profile'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Rails.application.routes.draw do
|
16
|
+
get '/profile/:id', as: :profile, controller: :user, action: :show
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_url_helpers_are_available
|
21
|
+
serializer = Class.new(ActiveModel::Serializer) do
|
22
|
+
attributes :url
|
23
|
+
|
24
|
+
def url
|
25
|
+
profile_url(id: object.object_id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
profile = Profile.new
|
29
|
+
|
30
|
+
assert_equal({ url: profile_url(id: profile.object_id) },
|
31
|
+
serializer.new(profile).as_json)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
- Yehuda Katz
|
9
|
+
- Santiago Pastorino
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: activemodel
|
@@ -17,100 +18,104 @@ dependencies:
|
|
17
18
|
requirements:
|
18
19
|
- - ">="
|
19
20
|
- !ruby/object:Gem::Version
|
20
|
-
version: '3.
|
21
|
+
version: '3.2'
|
21
22
|
type: :runtime
|
22
23
|
prerelease: false
|
23
24
|
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
27
|
-
version: '3.
|
28
|
+
version: '3.2'
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
30
|
name: rails
|
30
31
|
requirement: !ruby/object:Gem::Requirement
|
31
32
|
requirements:
|
32
33
|
- - ">="
|
33
34
|
- !ruby/object:Gem::Version
|
34
|
-
version: '3.
|
35
|
+
version: '3.2'
|
35
36
|
type: :development
|
36
37
|
prerelease: false
|
37
38
|
version_requirements: !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
40
|
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
|
-
version: '3.
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: pry
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: minitest
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
42
|
+
version: '3.2'
|
70
43
|
description: Making it easy to serialize models for client-side use
|
71
44
|
email:
|
72
45
|
- jose.valim@gmail.com
|
73
46
|
- wycats@gmail.com
|
47
|
+
- santiago@wyeworks.com
|
74
48
|
executables: []
|
75
49
|
extensions: []
|
76
50
|
extra_rdoc_files: []
|
77
51
|
files:
|
78
|
-
- ".gitignore"
|
79
|
-
- ".travis.yml"
|
80
52
|
- CHANGELOG.md
|
53
|
+
- CONTRIBUTING.md
|
81
54
|
- DESIGN.textile
|
82
|
-
-
|
83
|
-
- Gemfile.edge
|
84
|
-
- MIT-LICENSE.txt
|
55
|
+
- MIT-LICENSE
|
85
56
|
- README.md
|
86
|
-
- Rakefile
|
87
|
-
- active_model_serializers.gemspec
|
88
|
-
- bench/perf.rb
|
89
|
-
- cruft.md
|
90
57
|
- lib/action_controller/serialization.rb
|
58
|
+
- lib/action_controller/serialization_test_case.rb
|
91
59
|
- lib/active_model/array_serializer.rb
|
60
|
+
- lib/active_model/default_serializer.rb
|
61
|
+
- lib/active_model/serializable.rb
|
62
|
+
- lib/active_model/serializable/utils.rb
|
92
63
|
- lib/active_model/serializer.rb
|
93
|
-
- lib/active_model/serializer/
|
94
|
-
- lib/active_model/
|
64
|
+
- lib/active_model/serializer/association.rb
|
65
|
+
- lib/active_model/serializer/association/has_many.rb
|
66
|
+
- lib/active_model/serializer/association/has_one.rb
|
67
|
+
- lib/active_model/serializer/config.rb
|
68
|
+
- lib/active_model/serializer/generators/resource_override.rb
|
69
|
+
- lib/active_model/serializer/generators/serializer/USAGE
|
70
|
+
- lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb
|
71
|
+
- lib/active_model/serializer/generators/serializer/serializer_generator.rb
|
72
|
+
- lib/active_model/serializer/generators/serializer/templates/controller.rb
|
73
|
+
- lib/active_model/serializer/generators/serializer/templates/serializer.rb
|
74
|
+
- lib/active_model/serializer/railtie.rb
|
75
|
+
- lib/active_model/serializer/version.rb
|
76
|
+
- lib/active_model/serializer_support.rb
|
95
77
|
- lib/active_model_serializers.rb
|
96
|
-
- lib/
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
100
|
-
-
|
101
|
-
- test/
|
102
|
-
- test/
|
103
|
-
- test/
|
104
|
-
- test/
|
105
|
-
- test/
|
106
|
-
- test/
|
107
|
-
- test/
|
108
|
-
- test/serializer_support_test.rb
|
109
|
-
- test/serializer_test.rb
|
110
|
-
- test/test_fakes.rb
|
78
|
+
- lib/active_model_serializers/mime_types.rb
|
79
|
+
- test/fixtures/active_record.rb
|
80
|
+
- test/fixtures/poro.rb
|
81
|
+
- test/fixtures/template.html.erb
|
82
|
+
- test/integration/action_controller/namespaced_serialization_test.rb
|
83
|
+
- test/integration/action_controller/serialization_test.rb
|
84
|
+
- test/integration/action_controller/serialization_test_case_test.rb
|
85
|
+
- test/integration/active_record/active_record_test.rb
|
86
|
+
- test/integration/generators/resource_generator_test.rb
|
87
|
+
- test/integration/generators/scaffold_controller_generator_test.rb
|
88
|
+
- test/integration/generators/serializer_generator_test.rb
|
89
|
+
- test/test_app.rb
|
111
90
|
- test/test_helper.rb
|
91
|
+
- test/unit/active_model/array_serializer/except_test.rb
|
92
|
+
- test/unit/active_model/array_serializer/key_format_test.rb
|
93
|
+
- test/unit/active_model/array_serializer/meta_test.rb
|
94
|
+
- test/unit/active_model/array_serializer/only_test.rb
|
95
|
+
- test/unit/active_model/array_serializer/options_test.rb
|
96
|
+
- test/unit/active_model/array_serializer/root_test.rb
|
97
|
+
- test/unit/active_model/array_serializer/scope_test.rb
|
98
|
+
- test/unit/active_model/array_serializer/serialization_test.rb
|
99
|
+
- test/unit/active_model/default_serializer_test.rb
|
100
|
+
- test/unit/active_model/serializer/associations/build_serializer_test.rb
|
101
|
+
- test/unit/active_model/serializer/associations_test.rb
|
102
|
+
- test/unit/active_model/serializer/attributes_test.rb
|
103
|
+
- test/unit/active_model/serializer/config_test.rb
|
104
|
+
- test/unit/active_model/serializer/filter_test.rb
|
105
|
+
- test/unit/active_model/serializer/has_many_polymorphic_test.rb
|
106
|
+
- test/unit/active_model/serializer/has_many_test.rb
|
107
|
+
- test/unit/active_model/serializer/has_one_and_has_many_test.rb
|
108
|
+
- test/unit/active_model/serializer/has_one_polymorphic_test.rb
|
109
|
+
- test/unit/active_model/serializer/has_one_test.rb
|
110
|
+
- test/unit/active_model/serializer/key_format_test.rb
|
111
|
+
- test/unit/active_model/serializer/meta_test.rb
|
112
|
+
- test/unit/active_model/serializer/options_test.rb
|
113
|
+
- test/unit/active_model/serializer/root_test.rb
|
114
|
+
- test/unit/active_model/serializer/scope_test.rb
|
115
|
+
- test/unit/active_model/serializer/url_helpers_test.rb
|
112
116
|
homepage: https://github.com/rails-api/active_model_serializers
|
113
|
-
licenses:
|
117
|
+
licenses:
|
118
|
+
- MIT
|
114
119
|
metadata: {}
|
115
120
|
post_install_message:
|
116
121
|
rdoc_options: []
|
@@ -120,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
125
|
requirements:
|
121
126
|
- - ">="
|
122
127
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
128
|
+
version: 1.9.3
|
124
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
130
|
requirements:
|
126
131
|
- - ">="
|
@@ -128,9 +133,47 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
133
|
version: '0'
|
129
134
|
requirements: []
|
130
135
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.4.8
|
132
137
|
signing_key:
|
133
138
|
specification_version: 4
|
134
139
|
summary: Bringing consistency and object orientation to model serialization. Works
|
135
140
|
great for client-side MVC frameworks!
|
136
|
-
test_files:
|
141
|
+
test_files:
|
142
|
+
- test/fixtures/active_record.rb
|
143
|
+
- test/fixtures/poro.rb
|
144
|
+
- test/fixtures/template.html.erb
|
145
|
+
- test/integration/action_controller/namespaced_serialization_test.rb
|
146
|
+
- test/integration/action_controller/serialization_test.rb
|
147
|
+
- test/integration/action_controller/serialization_test_case_test.rb
|
148
|
+
- test/integration/active_record/active_record_test.rb
|
149
|
+
- test/integration/generators/resource_generator_test.rb
|
150
|
+
- test/integration/generators/scaffold_controller_generator_test.rb
|
151
|
+
- test/integration/generators/serializer_generator_test.rb
|
152
|
+
- test/test_app.rb
|
153
|
+
- test/test_helper.rb
|
154
|
+
- test/unit/active_model/array_serializer/except_test.rb
|
155
|
+
- test/unit/active_model/array_serializer/key_format_test.rb
|
156
|
+
- test/unit/active_model/array_serializer/meta_test.rb
|
157
|
+
- test/unit/active_model/array_serializer/only_test.rb
|
158
|
+
- test/unit/active_model/array_serializer/options_test.rb
|
159
|
+
- test/unit/active_model/array_serializer/root_test.rb
|
160
|
+
- test/unit/active_model/array_serializer/scope_test.rb
|
161
|
+
- test/unit/active_model/array_serializer/serialization_test.rb
|
162
|
+
- test/unit/active_model/default_serializer_test.rb
|
163
|
+
- test/unit/active_model/serializer/associations/build_serializer_test.rb
|
164
|
+
- test/unit/active_model/serializer/associations_test.rb
|
165
|
+
- test/unit/active_model/serializer/attributes_test.rb
|
166
|
+
- test/unit/active_model/serializer/config_test.rb
|
167
|
+
- test/unit/active_model/serializer/filter_test.rb
|
168
|
+
- test/unit/active_model/serializer/has_many_polymorphic_test.rb
|
169
|
+
- test/unit/active_model/serializer/has_many_test.rb
|
170
|
+
- test/unit/active_model/serializer/has_one_and_has_many_test.rb
|
171
|
+
- test/unit/active_model/serializer/has_one_polymorphic_test.rb
|
172
|
+
- test/unit/active_model/serializer/has_one_test.rb
|
173
|
+
- test/unit/active_model/serializer/key_format_test.rb
|
174
|
+
- test/unit/active_model/serializer/meta_test.rb
|
175
|
+
- test/unit/active_model/serializer/options_test.rb
|
176
|
+
- test/unit/active_model/serializer/root_test.rb
|
177
|
+
- test/unit/active_model/serializer/scope_test.rb
|
178
|
+
- test/unit/active_model/serializer/url_helpers_test.rb
|
179
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 1.8.7
|
4
|
-
- 1.9.2
|
5
|
-
- 1.9.3
|
6
|
-
- 2.0.0
|
7
|
-
- ree
|
8
|
-
- jruby-18mode
|
9
|
-
- jruby-19mode
|
10
|
-
- rbx-2
|
11
|
-
gemfile:
|
12
|
-
- Gemfile
|
13
|
-
- Gemfile.edge
|
14
|
-
matrix:
|
15
|
-
allow_failures:
|
16
|
-
- gemfile: Gemfile.edge
|
17
|
-
exclude:
|
18
|
-
# Edge Rails is only compatible with 1.9.3
|
19
|
-
- gemfile: Gemfile.edge
|
20
|
-
rvm: 1.8.7
|
21
|
-
- gemfile: Gemfile.edge
|
22
|
-
rvm: 1.9.2
|
23
|
-
- gemfile: Gemfile.edge
|
24
|
-
rvm: ree
|
25
|
-
- gemfile: Gemfile.edge
|
26
|
-
rvm: jruby-18mode
|
27
|
-
- gemfile: Gemfile.edge
|
28
|
-
rvm: rbx-18mode
|
data/Gemfile
DELETED
data/Gemfile.edge
DELETED
data/Rakefile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
require "rake/testtask"
|
4
|
-
|
5
|
-
desc 'Run tests'
|
6
|
-
Rake::TestTask.new(:test) do |t|
|
7
|
-
t.libs << 'lib'
|
8
|
-
t.libs << 'test'
|
9
|
-
t.pattern = 'test/**/*_test.rb'
|
10
|
-
t.verbose = true
|
11
|
-
end
|
12
|
-
|
13
|
-
desc 'Benchmark'
|
14
|
-
task :bench do
|
15
|
-
load 'bench/perf.rb'
|
16
|
-
end
|
17
|
-
|
18
|
-
task :default => :test
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
$:.unshift File.expand_path("../lib", __FILE__)
|
4
|
-
require "active_model/serializers/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.authors = ["José Valim", "Yehuda Katz"]
|
8
|
-
gem.email = ["jose.valim@gmail.com", "wycats@gmail.com"]
|
9
|
-
gem.description = %q{Making it easy to serialize models for client-side use}
|
10
|
-
gem.summary = %q{Bringing consistency and object orientation to model serialization. Works great for client-side MVC frameworks!}
|
11
|
-
gem.homepage = "https://github.com/rails-api/active_model_serializers"
|
12
|
-
|
13
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
-
gem.files = `git ls-files`.split("\n")
|
15
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
-
gem.name = "active_model_serializers"
|
17
|
-
gem.require_paths = ["lib"]
|
18
|
-
gem.version = ActiveModel::Serializer::VERSION
|
19
|
-
|
20
|
-
gem.add_dependency 'activemodel', '>= 3.0'
|
21
|
-
gem.add_development_dependency "rails", ">= 3.0"
|
22
|
-
gem.add_development_dependency "pry"
|
23
|
-
gem.add_development_dependency "minitest"
|
24
|
-
end
|
data/bench/perf.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
require "active_model_serializers"
|
4
|
-
require "active_support/json"
|
5
|
-
require "benchmark"
|
6
|
-
|
7
|
-
class User < Struct.new(:id,:name,:age,:about)
|
8
|
-
include ActiveModel::SerializerSupport
|
9
|
-
|
10
|
-
def fast_hash
|
11
|
-
h = {
|
12
|
-
id: read_attribute_for_serialization(:id),
|
13
|
-
name: read_attribute_for_serialization(:name),
|
14
|
-
about: read_attribute_for_serialization(:about)
|
15
|
-
}
|
16
|
-
h[:age] = read_attribute_for_serialization(:age) if age > 18
|
17
|
-
h
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class UserSerializer < ActiveModel::Serializer
|
22
|
-
attributes :id, :name, :age, :about
|
23
|
-
|
24
|
-
def include_age?
|
25
|
-
object.age > 18
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
u = User.new(1, "sam", 10, "about")
|
32
|
-
s = UserSerializer.new(u)
|
33
|
-
|
34
|
-
n = 100000
|
35
|
-
|
36
|
-
Benchmark.bmbm {|x|
|
37
|
-
x.report("init") { n.times { UserSerializer.new(u) } }
|
38
|
-
x.report("fast_hash") { n.times { u.fast_hash } }
|
39
|
-
x.report("attributes") { n.times { UserSerializer.new(u).attributes } }
|
40
|
-
x.report("serializable_hash") { n.times { UserSerializer.new(u).serializable_hash } }
|
41
|
-
}
|
42
|
-
|
43
|
-
|
data/cruft.md
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
As of Ruby 1.9.3, it is impossible to dynamically generate a Symbol
|
2
|
-
through interpolation without generating garbage. Theoretically, Ruby
|
3
|
-
should be able to take care of this by building up the String in C and
|
4
|
-
interning the C String.
|
5
|
-
|
6
|
-
Because of this, we avoid generating dynamic Symbols at runtime. For
|
7
|
-
example, instead of generating the instrumentation event dynamically, we
|
8
|
-
have a constant with a Hash of events:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
INSTRUMENT = {
|
12
|
-
:serialize => :"serialize.serializer",
|
13
|
-
:associations => :"associations.serializer"
|
14
|
-
}
|
15
|
-
```
|
16
|
-
|
17
|
-
If Ruby ever fixes this issue and avoids generating garbage with dynamic
|
18
|
-
symbols, this code can be removed.
|
19
|
-
|