granola 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61316a397f01835165e7961ce698174bbf8c3c26
4
- data.tar.gz: 9287b8229f817fbe765051a4f3b066601740d6af
3
+ metadata.gz: c8736dc4a00f68a43630c02a5fd3f3aa21c46269
4
+ data.tar.gz: 2aabc2032b24dfe14a2ef9f08bcf088d0bb8f129
5
5
  SHA512:
6
- metadata.gz: cfeacf1ba025637fa153c3e437a22128a355d8d948b34c638aed537dd3b7d136fde490fcac0c1e87c2dd0faa1b056d2363855ed5cf28e2f1125183f91db92a84
7
- data.tar.gz: c13007b46a27490727db0ceb9fbb5cc9ed7ca8ff246ce9115e4a913467c47f76952a7fd72ec470128c82107415d16f44b345339c669c3a4a600187c6811cdf41
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 uses [MultiJson][] to serialize your objects with your
34
- favorite backend.
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
- Try to avoid using the default, which is the `stdlib`'s pure-ruby JSON library,
37
- since it's slow. If in doubt, I like [Yajl][].
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
@@ -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 string using the current MultiJson adapter.
54
+ # Public: Generate the JSON String.
39
55
  #
40
- # **options - Any options valid for `MultiJson.dump`.
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
- MultiJson.dump(attributes, options)
60
+ Granola.json.(attributes, options)
45
61
  end
46
62
 
47
63
  # Public: Returns the MIME type generated by this serializer. By default
@@ -1,3 +1,3 @@
1
1
  module Granola
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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: 2014-11-11 00:00:00.000000000 Z
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: '1.5'
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: '1.5'
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