granola 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -8
- data/lib/granola.rb +20 -4
- data/lib/granola/version.rb +1 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8736dc4a00f68a43630c02a5fd3f3aa21c46269
|
4
|
+
data.tar.gz: 2aabc2032b24dfe14a2ef9f08bcf088d0bb8f129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 688ceebc2a8cdcf7931d00359d3a31829d3fc0a05db7ffbf556ff99d195f4ffdc2f96b5c942be9a7f9ecc0d7b8a8702f9aa632c91d8b7fc636a446c01a134481
|
7
|
+
data.tar.gz: 633293c6115d1d81558932f7f04bdbf33b8a2b880e0e9fdef5b95f7e5edc20ac44b1a84951192e4652f249bc7c65cee29f29d04c48a63c12efc213fc11434edc
|
data/README.md
CHANGED
@@ -30,16 +30,13 @@ PersonSerializer.new(person).to_json #=> '{"name":"John Doe",...}'
|
|
30
30
|
## JSON serialization
|
31
31
|
|
32
32
|
Granola doesn't make assumptions about your code, so it shouldn't depend on a
|
33
|
-
specific JSON backend. It
|
34
|
-
|
33
|
+
specific JSON backend. It defaults to the native JSON backend, but you're free
|
34
|
+
to change it. For example, if you were using [Yajl][]:
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
If you want to pass options to `MultiJson` (like `pretty: true`), any keywords
|
40
|
-
passed to `#to_json` will be forwarded to `MultiJson.dump`.
|
36
|
+
``` ruby
|
37
|
+
Granola.json = ->(obj, **opts) { Yajl::Encoder.encode(obj, opts) }
|
38
|
+
```
|
41
39
|
|
42
|
-
[MultiJson]: https://github.com/intridea/multi_json
|
43
40
|
[Yajl]: https://github.com/brianmario/yajl-ruby
|
44
41
|
|
45
42
|
## Handling lists of models
|
data/lib/granola.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
|
-
require "multi_json"
|
2
1
|
require "granola/version"
|
2
|
+
require "json"
|
3
3
|
|
4
4
|
module Granola
|
5
|
+
class << self
|
6
|
+
# Public: Get/Set a Proc that takes an Object and a Hash of options and
|
7
|
+
# returns a JSON String.
|
8
|
+
#
|
9
|
+
# The default implementation uses the standard library's JSON module, but
|
10
|
+
# you're welcome to swap it out.
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# require "yajl"
|
15
|
+
# Granola.json = ->(obj, **opts) { Yajl::Encoder.encode(obj, opts) }
|
16
|
+
attr_accessor :json
|
17
|
+
end
|
18
|
+
|
19
|
+
self.json = ->(obj, **opts) { JSON.dump(obj) }
|
20
|
+
|
5
21
|
# A Serializer describes how to serialize a certain type of object, by
|
6
22
|
# declaring the structure of JSON objects.
|
7
23
|
class Serializer
|
@@ -35,13 +51,13 @@ module Granola
|
|
35
51
|
fail NotImplementedError
|
36
52
|
end
|
37
53
|
|
38
|
-
# Public: Generate the JSON
|
54
|
+
# Public: Generate the JSON String.
|
39
55
|
#
|
40
|
-
# **options - Any options
|
56
|
+
# **options - Any options to be passed to the `Granola.json` Proc.
|
41
57
|
#
|
42
58
|
# Returns a String.
|
43
59
|
def to_json(**options)
|
44
|
-
|
60
|
+
Granola.json.(attributes, options)
|
45
61
|
end
|
46
62
|
|
47
63
|
# Public: Returns the MIME type generated by this serializer. By default
|
data/lib/granola/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: granola
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Sanguinetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: multi_json
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.10'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.10'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: cutest
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +30,14 @@ dependencies:
|
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
33
|
+
version: '2.5'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
40
|
+
version: '2.5'
|
55
41
|
description: Granola is a very simple and fast library to turn your models to JSON
|
56
42
|
email:
|
57
43
|
- contacto@nicolassanguinetti.info
|