restpack_serializer 0.4.13 → 0.4.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/README.md +34 -1
- data/lib/restpack_serializer.rb +1 -0
- data/lib/restpack_serializer/version.rb +1 -1
- data/restpack_serializer.gemspec +5 -5
- metadata +9 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a00410f5da13a4809d6e34a2691b65e7c17489c
|
4
|
+
data.tar.gz: f98e7fff30aefe3a917653a6d6407e22077bee8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1b0bf8aac3022e67127598e102f0890e5d5476419914e03240faa156128ee4acdc3f12604c6cfdee98545e9bd0347447acbe52978a3b23f2f7373f87008b54a
|
7
|
+
data.tar.gz: eee7830a50cc6c9e1808d68c67568d9c1493ae8aa4634a1c6261bf0628f2036ad2d4e8b3f6293ca3db0d8f92ff55a8a3e2d1035184167500f0060755cabf8de8
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -46,6 +46,27 @@ end
|
|
46
46
|
}
|
47
47
|
```
|
48
48
|
|
49
|
+
`as_json` accepts an optional `context` hash parameter which can be used be your Serializers to customize their output:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
class AlbumSerializer
|
53
|
+
include RestPack::Serializer
|
54
|
+
attributes :id, :title, :year, :artist_id, :extras
|
55
|
+
can_include :artists, :songs
|
56
|
+
can_filter_by :year
|
57
|
+
|
58
|
+
def extras
|
59
|
+
if @context[:admin?]
|
60
|
+
{ markup_percent: 95 }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
AlbumSerializer.as_json(album, { admin?: true })
|
68
|
+
```
|
69
|
+
|
49
70
|
## Exposing an API
|
50
71
|
|
51
72
|
The `AlbumSerializer` provides `page` and `resource` methods which provide paged collection and singular resource GET endpoints.
|
@@ -67,12 +88,24 @@ These endpoint will live at URLs such as `/albums` and `/albums/142857`:
|
|
67
88
|
* http://restpack-serializer-sample.herokuapp.com/api/v1/albums.json
|
68
89
|
* http://restpack-serializer-sample.herokuapp.com/api/v1/albums/4.json
|
69
90
|
|
70
|
-
|
91
|
+
The `AlbumSerializer` also provides a `single` method which will return a serialized resource similar to `as_json` above.
|
92
|
+
|
93
|
+
`page`, `resource` and `single` methods take an optional scope argument allowing us to enforce arbitrary constraints:
|
71
94
|
|
72
95
|
```ruby
|
73
96
|
AlbumSerializer.page(params, Albums.where("year < 1950"))
|
74
97
|
```
|
75
98
|
|
99
|
+
In addition to `scope`, all three methods also accept an optional `context` hash:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
AlbumSerializer.page(params, Albums.where("year < 1950"), { admin?: true })
|
103
|
+
```
|
104
|
+
|
105
|
+
Other features:
|
106
|
+
* [Dynamically Include/Exclude Attributes](https://github.com/RestPack/restpack_serializer/blob/master/spec/serializable/serializer_spec.rb#L42)
|
107
|
+
* [Custom Attributes Hash](https://github.com/RestPack/restpack_serializer/blob/master/spec/serializable/serializer_spec.rb#L46)
|
108
|
+
|
76
109
|
## Paging
|
77
110
|
|
78
111
|
Collections are paged by default. `page` and `page_size` parameters are available:
|
data/lib/restpack_serializer.rb
CHANGED
data/restpack_serializer.gemspec
CHANGED
@@ -17,12 +17,12 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency 'activerecord', '~> 4.0'
|
21
|
-
gem.add_dependency 'activesupport', '~> 4.0'
|
22
|
-
gem.add_dependency 'protected_attributes', '~> 1.0.
|
23
|
-
gem.add_dependency 'will_paginate', '~> 3.0'
|
24
|
-
gem.add_dependency 'restpack_gem', '~> 0.0.9'
|
20
|
+
gem.add_dependency 'activerecord', '~> 4.0.3'
|
21
|
+
gem.add_dependency 'activesupport', '~> 4.0.3'
|
22
|
+
# gem.add_dependency 'protected_attributes', '~> 1.0.5'
|
23
|
+
gem.add_dependency 'will_paginate', '~> 3.0.5'
|
25
24
|
|
25
|
+
gem.add_development_dependency 'restpack_gem', '~> 0.0.9'
|
26
26
|
gem.add_development_dependency 'rake', '~> 10.0.3'
|
27
27
|
gem.add_development_dependency 'rspec', '~> 2.12'
|
28
28
|
gem.add_development_dependency 'guard-rspec', '~> 2.5.4'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,56 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.3
|
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:
|
26
|
+
version: 4.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.0.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: protected_attributes
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.0.3
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.0.3
|
40
|
+
version: 4.0.3
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: will_paginate
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - ~>
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
47
|
+
version: 3.0.5
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - ~>
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
54
|
+
version: 3.0.5
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: restpack_gem
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +59,7 @@ dependencies:
|
|
73
59
|
- - ~>
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: 0.0.9
|
76
|
-
type: :
|
62
|
+
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|