Skip to content

Commit 01d4f04

Browse files
committed
Merge branch 'master' into 0-10-stable
2 parents f353ded + 28b8e3d commit 01d4f04

File tree

14 files changed

+99
-49
lines changed

14 files changed

+99
-49
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ rvm:
77
- 2.2.6
88
- 2.3.3
99
- ruby-head
10-
- jruby-9.0.4.0
10+
- jruby-9.1.5.0 # is precompiled per http://rubies.travis-ci.org/
1111
- jruby-head
1212

1313
jdk:
1414
- oraclejdk8
1515

16+
before_install:
17+
- gem update --system
18+
- rvm @global do gem uninstall bundler -a -x
19+
- rvm @global do gem install bundler -v 1.13.7
1620
install: bundle install --path=vendor/bundle --retry=3 --jobs=3
1721
cache:
1822
directories:
@@ -35,13 +39,13 @@ matrix:
3539
exclude:
3640
- rvm: 2.1
3741
env: RAILS_VERSION=master
38-
- rvm: jruby-9.0.4.0
42+
- rvm: jruby-9.1.5.0
3943
env: RAILS_VERSION=master
4044
- rvm: jruby-head
4145
env: RAILS_VERSION=master
4246
- rvm: 2.1
4347
env: RAILS_VERSION=5.0
44-
- rvm: jruby-9.0.4.0
48+
- rvm: jruby-9.1.5.0
4549
env: RAILS_VERSION=5.0
4650
- rvm: jruby-head
4751
env: RAILS_VERSION=5.0

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 0.10.x
22

3-
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.4...master)
3+
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...master)
44

55
Breaking changes:
66

@@ -14,8 +14,29 @@ Fixes:
1414

1515
Misc:
1616

17+
### [v0.10.5 (2017-03-07)](https://github.com/rails-api/active_model_serializers/compare/v0.10.4...v0.10.5)
18+
19+
Breaking changes:
20+
21+
Features:
22+
23+
- [#2021](https://github.com/rails-api/active_model_serializers/pull/2021) ActiveModelSerializers::Model#attributes. Originally in [#1982](https://github.com/rails-api/active_model_serializers/pull/1982). (@bf4)
24+
- [#2057](https://github.com/rails-api/active_model_serializers/pull/2057)
25+
Update version constraint for jsonapi-renderer to `['>= 0.1.1.beta1', '< 0.2']`
26+
(@jaredbeck)
27+
28+
Fixes:
29+
30+
- [#2022](https://github.com/rails-api/active_model_serializers/pull/2022) Mutation of ActiveModelSerializers::Model now changes the attributes. Originally in [#1984](https://github.com/rails-api/active_model_serializers/pull/1984). (@bf4)
31+
32+
Misc:
33+
34+
- [#2055](https://github.com/rails-api/active_model_serializers/pull/2055)
35+
Replace deprecated dependency jsonapi with jsonapi-renderer. (@jaredbeck)
1736
- [#2021](https://github.com/rails-api/active_model_serializers/pull/2021) Make test attributes explicit. Tests have Model#associations. (@bf4)
1837
- [#1981](https://github.com/rails-api/active_model_serializers/pull/1981) Fix relationship link documentation. (@groyoh)
38+
- [#2035](https://github.com/rails-api/active_model_serializers/pull/2035) Document how to disable the logger. (@MSathieu)
39+
- [#2039](https://github.com/rails-api/active_model_serializers/pull/2039) Documentation fixes. (@biow0lf)
1940

2041
### [v0.10.4 (2017-01-06)](https://github.com/rails-api/active_model_serializers/compare/v0.10.3...v0.10.4)
2142

active_model_serializers.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
4242
# 'minitest'
4343
# 'thread_safe'
4444

45-
spec.add_runtime_dependency 'jsonapi', '0.1.1.beta6'
45+
spec.add_runtime_dependency 'jsonapi-renderer', ['>= 0.1.1.beta1', '< 0.2']
4646
spec.add_runtime_dependency 'case_transform', '>= 0.2'
4747

4848
spec.add_development_dependency 'activerecord', rails_versions

appveyor.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '{build}'
1+
version: 1.0.{build}-{branch}
22

33
skip_tags: true
44

@@ -7,17 +7,23 @@ environment:
77
matrix:
88
- ruby_version: "Ruby21"
99
- ruby_version: "Ruby21-x64"
10-
- ruby_version: "jruby-9.0.0.0"
1110

1211
cache:
1312
- vendor/bundle
1413

1514
install:
1615
- SET PATH=C:\%ruby_version%\bin;%PATH%
17-
- gem install bundler
16+
- gem update --system
17+
- gem uninstall bundler -a -x
18+
- gem install bundler -v 1.13.7
1819
- bundle env
1920
- bundle install --path=vendor/bundle --retry=3 --jobs=3
2021

22+
before_test:
23+
- ruby -v
24+
- gem -v
25+
- bundle -v
26+
2127
test_script:
2228
- bundle exec rake ci
2329

docs/general/logging.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ You may customize the logger in an initializer, for example:
1212
```ruby
1313
ActiveModelSerializers.logger = Logger.new(STDOUT)
1414
```
15+
16+
You can also disable the logger, just put this in `config/initializers/active_model_serializers.rb`:
17+
18+
```ruby
19+
require 'active_model_serializers'
20+
ActiveSupport::Notifications.unsubscribe(ActiveModelSerializers::Logging::RENDER_EVENT)
21+
```

docs/general/serializers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ With the `:json` adapter, the previous serializer would be rendered as:
225225
link :self do
226226
href "https://example.com/link_author/#{object.id}"
227227
end
228-
link :author { link_author_url(object) }
229-
link :link_authors { link_authors_url }
228+
link(:author) { link_author_url(object) }
229+
link(:link_authors) { link_authors_url }
230230
link :other, 'https://example.com/resource'
231-
link :posts { link_author_posts_url(object) }
231+
link(:posts) { link_author_posts_url(object) }
232232
```
233233

234234
#### #object

docs/howto/add_pagination_links.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ If you are using `JSON` adapter, pagination links will not be included automatic
7777
Add this method to your base API controller.
7878

7979
```ruby
80-
def pagination_dict(object)
80+
def pagination_dict(collection)
8181
{
82-
current_page: object.current_page,
83-
next_page: object.next_page,
84-
prev_page: object.prev_page, # use object.previous_page when using will_paginate
85-
total_pages: object.total_pages,
86-
total_count: object.total_count
82+
current_page: collection.current_page,
83+
next_page: collection.next_page,
84+
prev_page: collection.prev_page, # use collection.previous_page when using will_paginate
85+
total_pages: collection.total_pages,
86+
total_count: collection.total_count
8787
}
8888
end
8989
```
@@ -117,18 +117,18 @@ ex.
117117
You can also achieve the same result if you have a helper method that adds the pagination info in the meta tag. For instance, in your action specify a custom serializer.
118118

119119
```ruby
120-
render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@post)
120+
render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@posts)
121121
```
122122

123123
```ruby
124124
#expects pagination!
125-
def meta_attributes(resource, extra_meta = {})
125+
def meta_attributes(collection, extra_meta = {})
126126
{
127-
current_page: resource.current_page,
128-
next_page: resource.next_page,
129-
prev_page: resource.prev_page, # use resource.previous_page when using will_paginate
130-
total_pages: resource.total_pages,
131-
total_count: resource.total_count
127+
current_page: collection.current_page,
128+
next_page: collection.next_page,
129+
prev_page: collection.prev_page, # use collection.previous_page when using will_paginate
130+
total_pages: collection.total_pages,
131+
total_count: collection.total_count
132132
}.merge(extra_meta)
133133
end
134134
```

docs/howto/outside_controller_use.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ In ActiveModelSerializers versions 0.10 or later, serializing resources outside
1010
# Create our resource
1111
post = Post.create(title: "Sample post", body: "I love Active Model Serializers!")
1212

13-
# Optional options parameters
14-
options = {}
13+
# Optional options parameters for both the serializer and instance
14+
options = {serializer: PostDetailedSerializer, username: 'sample user'}
1515

1616
# Create a serializable resource instance
1717
serializable_resource = ActiveModelSerializers::SerializableResource.new(post, options)
@@ -20,6 +20,7 @@ serializable_resource = ActiveModelSerializers::SerializableResource.new(post, o
2020
model_json = serializable_resource.as_json
2121
```
2222
The object that is passed to `ActiveModelSerializers::SerializableResource.new` can be a single resource or a collection.
23+
The additional options are the same options that are passed [through controllers](../general/rendering.md#explicit-serializer).
2324

2425
### Looking up the Serializer for a Resource
2526

docs/howto/serialize_poro.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,32 @@ end
4242

4343
The default serializer would be `MyModelSerializer`.
4444

45+
*IMPORTANT*: There is a surprising behavior (bug) in the current implementation of ActiveModelSerializers::Model that
46+
prevents an accessor from modifying attributes on the instance. The fix for this bug
47+
is a breaking change, so we have made an opt-in configuration.
48+
49+
New applications should set:
50+
51+
```ruby
52+
ActiveModelSerializers::Model.derive_attributes_from_names_and_fix_accessors
53+
```
54+
55+
Existing applications can use the fix *and* avoid breaking changes
56+
by making a superclass for new models. For example:
57+
58+
```ruby
59+
class SerializablePoro < ActiveModelSerializers::Model
60+
derive_attributes_from_names_and_fix_accessors
61+
end
62+
```
63+
64+
So that `MyModel` above would inherit from `SerializablePoro`.
65+
66+
`derive_attributes_from_names_and_fix_accessors` prepends the `DeriveAttributesFromNamesAndFixAccessors`
67+
module and does the following:
68+
69+
- `id` will *always* be in the attributes. (This is until we separate out the caching requirement for POROs.)
70+
- Overwrites the `attributes` method to that it only returns declared attributes.
71+
`attributes` will now be a frozen hash with indifferent access.
72+
4573
For more information, see [README: What does a 'serializable resource' look like?](../../README.md#what-does-a-serializable-resource-look-like).

docs/howto/upgrade_from_0_8_to_0_10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ end
107107

108108
```
109109
Add this class to your app however you see fit. This is the class that your existing serializers
110-
that inherit from `ActiveMode::Serializer` should inherit from.
110+
that inherit from `ActiveModel::Serializer` should inherit from.
111111

112112
### 3. Add `ActiveModel::V08::CollectionSerializer`
113113
```ruby

0 commit comments

Comments
 (0)