jsonapi-serializers 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +39 -35
- data/jsonapi-serializers.gemspec +1 -1
- data/lib/jsonapi-serializers/attributes.rb +4 -4
- data/lib/jsonapi-serializers/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5be9e7db5c661af3677e1ddc65deccbf2e9aa53
|
4
|
+
data.tar.gz: 27457e4e784106807993d0374de6e131dd890a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a936a8f8d1b73c1aca370a7db10440a9ce9fe854828eecf69b7cb98c6b623f5e573e06638e5efee9f471117a38869b5678ef531262fed69d451e28cc882989b
|
7
|
+
data.tar.gz: f35e15687ce5b6038c47f721cbb4e242b57d34bcf7b338b422b46420f685e52bcb1d3fdf56aea399e8dc5815d208984ac8ab58acc8daef14013d67298b48f470
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# JSONAPI::Serializers
|
2
2
|
|
3
|
+
[](https://travis-ci.org/fotinakis/jsonapi-serializers)
|
4
|
+
[](http://badge.fury.io/rb/jsonapi-serializers)
|
5
|
+
|
6
|
+
|
3
7
|
JSONAPI::Serializers is a simple library for serializing Ruby objects and their relationships into the [JSON:API format](http://jsonapi.org/format/).
|
4
8
|
|
5
9
|
As of writing, the JSON:API spec is approaching v1 and still undergoing changes. This library supports RC3+ and aims to keep up with the continuing development changes.
|
@@ -161,55 +165,55 @@ The block is evaluated within the serializer instance, so it has access to the `
|
|
161
165
|
Many other formatting and customizations are possible by overriding any of the following instance methods on your serializers.
|
162
166
|
|
163
167
|
```ruby
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
168
|
+
# Override this to customize the JSON:API "id" for this object.
|
169
|
+
# Always return a string from this method to conform with the JSON:API spec.
|
170
|
+
def id
|
171
|
+
object.id.to_s
|
172
|
+
end
|
169
173
|
```
|
170
174
|
```ruby
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
175
|
+
# Override this to customize the JSON:API "type" for this object.
|
176
|
+
# By default, the type is the object's class name lowercased, pluralized, and dasherized,
|
177
|
+
# per the spec naming recommendations: http://jsonapi.org/recommendations/#naming
|
178
|
+
# For example, 'MyApp::LongCommment' will become the 'long-comments' type.
|
179
|
+
def type
|
180
|
+
object.class.name.demodulize.tableize.dasherize
|
181
|
+
end
|
178
182
|
```
|
179
183
|
```ruby
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
184
|
+
# Override this to customize how attribute names are formatted.
|
185
|
+
# By default, attribute names are dasherized per the spec naming recommendations:
|
186
|
+
# http://jsonapi.org/recommendations/#naming
|
187
|
+
def format_name(attribute_name)
|
188
|
+
attribute_name.to_s.dasherize
|
189
|
+
end
|
186
190
|
```
|
187
191
|
```ruby
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
+
# The opposite of format_name. Override this if you override format_name.
|
193
|
+
def unformat_name(attribute_name)
|
194
|
+
attribute_name.to_s.underscore
|
195
|
+
end
|
192
196
|
```
|
193
197
|
```ruby
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
+
# Override this to provide resource-object metadata.
|
199
|
+
# http://jsonapi.org/format/#document-structure-resource-objects
|
200
|
+
def meta
|
201
|
+
end
|
198
202
|
```
|
199
203
|
```ruby
|
200
|
-
|
201
|
-
|
202
|
-
|
204
|
+
def self_link
|
205
|
+
"/#{type}/#{id}"
|
206
|
+
end
|
203
207
|
```
|
204
208
|
```ruby
|
205
|
-
|
206
|
-
|
207
|
-
|
209
|
+
def relationship_self_link(attribute_name)
|
210
|
+
"#{self_link}/links/#{format_name(attribute_name)}"
|
211
|
+
end
|
208
212
|
```
|
209
213
|
```ruby
|
210
|
-
|
211
|
-
|
212
|
-
|
214
|
+
def relationship_related_link(attribute_name)
|
215
|
+
"#{self_link}/#{format_name(attribute_name)}"
|
216
|
+
end
|
213
217
|
```
|
214
218
|
|
215
219
|
## Relationships
|
data/jsonapi-serializers.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = JSONAPI::Serializer::VERSION
|
9
9
|
spec.authors = ["Mike Fotinakis"]
|
10
10
|
spec.email = ["mike@fotinakis.com"]
|
11
|
-
spec.summary = %q{Pure Ruby serializers
|
11
|
+
spec.summary = %q{Pure Ruby readonly serializers for the JSON:API spec.}
|
12
12
|
spec.description = %q{}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
@@ -17,12 +17,12 @@ module JSONAPI
|
|
17
17
|
add_attribute(name, options, &block)
|
18
18
|
end
|
19
19
|
|
20
|
-
def has_one(name, options = {})
|
21
|
-
add_to_one_association(name, options)
|
20
|
+
def has_one(name, options = {}, &block)
|
21
|
+
add_to_one_association(name, options, &block)
|
22
22
|
end
|
23
23
|
|
24
|
-
def has_many(name, options = {})
|
25
|
-
add_to_many_association(name, options)
|
24
|
+
def has_many(name, options = {}, &block)
|
25
|
+
add_to_many_association(name, options, &block)
|
26
26
|
end
|
27
27
|
|
28
28
|
def add_attribute(name, options = {}, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Fotinakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -126,7 +126,7 @@ rubyforge_project:
|
|
126
126
|
rubygems_version: 2.2.2
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
|
-
summary: Pure Ruby serializers
|
129
|
+
summary: Pure Ruby readonly serializers for the JSON:API spec.
|
130
130
|
test_files:
|
131
131
|
- spec/serializer_spec.rb
|
132
132
|
- spec/spec_helper.rb
|