sinatra-active-model-serializers 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +17 -5
- data/lib/sinatra-active-model-serializers/json.rb +1 -3
- data/lib/sinatra-active-model-serializers/version.rb +2 -2
- data/spec/app/application.rb +7 -0
- data/spec/json_spec.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eee1dfba4d6f3e8f8f560b5877e31c74f7d21a2
|
4
|
+
data.tar.gz: d524672188df09d01cdfe9b0ead8114a6b83ca7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0121b5801dee190060a47df5049f06056a61bcb8dc79bf4fa4002ed77811bb42bf47d3d21a9bac3a57e2e07c782528d4ada0e5a4284f2b3e520d2be54a4ef2ac
|
7
|
+
data.tar.gz: 845b7be3d130fc90ea7cafb035451c9d2531a9c1890d420e1d4cab88d747307827849158f47842ddf78fc7fe72de7eeb93877822ccc6dc92f86608daa15af3d7
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -44,9 +44,9 @@ class App < Sinatra::Base
|
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
|
-
##
|
47
|
+
## Sets
|
48
48
|
|
49
|
-
|
49
|
+
#### active_model_serializers
|
50
50
|
|
51
51
|
This attribute is an object, all inserted configuration this object it will be passed on to Active Model Serializers, eg.
|
52
52
|
|
@@ -54,7 +54,7 @@ This attribute is an object, all inserted configuration this object it will be p
|
|
54
54
|
set :active_model_serializers, { root: false }
|
55
55
|
```
|
56
56
|
|
57
|
-
|
57
|
+
#### serializers_path
|
58
58
|
|
59
59
|
By default this attribute is set up to look for the serializers from your project in "* app / serializers *". Whether you have a different environment you can set up by inserting the path of the string, eg.
|
60
60
|
|
@@ -68,18 +68,20 @@ or not to automatically requires
|
|
68
68
|
set :serializers_path, false
|
69
69
|
```
|
70
70
|
|
71
|
-
|
71
|
+
## Response JSON
|
72
72
|
|
73
73
|
When you return a json, you can send a the second parameter.
|
74
74
|
This the second parameter is an object. This object may contain new configurations to assign to the Active Model Serializers or to rewrite any already set by default, eg.
|
75
75
|
|
76
|
+
#### root
|
77
|
+
|
76
78
|
```
|
77
79
|
get '/' do
|
78
80
|
json Resource.first, { root: false }
|
79
81
|
end
|
80
82
|
```
|
81
83
|
|
82
|
-
|
84
|
+
#### scope
|
83
85
|
|
84
86
|
```
|
85
87
|
get '/' do
|
@@ -87,6 +89,16 @@ get '/' do
|
|
87
89
|
end
|
88
90
|
```
|
89
91
|
|
92
|
+
#### serializer
|
93
|
+
|
94
|
+
If you wish to use an another serializer than the default, you can explicitly pass it through the renderer
|
95
|
+
|
96
|
+
1. For a resource:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
json Resource.first, { serializer: ResourcePreviewSerializer }
|
100
|
+
```
|
101
|
+
|
90
102
|
## License
|
91
103
|
|
92
104
|
[MIT](https://github.com/SauloSilva/sinatra-active-model-serializers/blob/master/LICENSE)
|
@@ -10,9 +10,7 @@ module Sinatra
|
|
10
10
|
def json(object, options={})
|
11
11
|
options = options.merge(settings.active_model_serializers)
|
12
12
|
|
13
|
-
serializer = ActiveModel::Serializer.serializer_for(object, options)
|
14
|
-
|
15
|
-
if serializer
|
13
|
+
if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(object, options))
|
16
14
|
serializer.new(object, options).to_json
|
17
15
|
else
|
18
16
|
object.to_json(options)
|
data/spec/app/application.rb
CHANGED
data/spec/json_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-active-model-serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saulosantiago
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|