restpack_serializer 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b77fdb73dff82ed326e500a577591bb9f00161d
4
- data.tar.gz: 4acf7fecedb94d8ec651e4cbb5d23e140972f2c6
3
+ metadata.gz: b1a8ecbc65ea8b809a06673e5ef2384b5604bf83
4
+ data.tar.gz: 53ae8aaec67aecff3a180d47574db826419f1f82
5
5
  SHA512:
6
- metadata.gz: 5ef69c7c2cb0d391c66f88050f07b41f5c175b5448d48b75cde0c11d96d4f6d96e30680bcd5254119268148835fa876fc97b6fffe433318796455da96c5b2661
7
- data.tar.gz: e97576009dca585897d02894416520033ced2198dd7147f13b176d35591d892562e9fbda2d3d7a9daa854846f5ade585282b13c18cd21807be28cea59a8164fc
6
+ metadata.gz: 64020419cc8a025d86b568c63b2a6d3efbcd422a19a1cc17133a0676a536e0307e18074e81be9d35bb24c862c10ff685c81984a17b81c6a271c713c2f8c36cde
7
+ data.tar.gz: a33dd4d6cb45d530ae2520dbf01675e4ebf8896f7b3bf2d17e322a044930a27b7d412fcdbe6d83b272e739a1c766c7db7860d7e404da8af26ebe2652c48863f3
@@ -50,6 +50,11 @@ module RestPack
50
50
  add_custom_attributes(data)
51
51
  add_links(model, data) unless self.class.associations.empty?
52
52
 
53
+ data
54
+ end
55
+
56
+ def as_json_symbolized(model, context = {})
57
+ data = as_json(model, context)
53
58
  Symbolizer.recursive_symbolize(data)
54
59
  end
55
60
 
@@ -99,6 +104,10 @@ module RestPack
99
104
  new.as_json(model, context)
100
105
  end
101
106
 
107
+ def as_json_symbolized(model, context = {})
108
+ new.as_json_symbolized(model, context)
109
+ end
110
+
102
111
  def serialize(models, context = {})
103
112
  models = [models] unless models.kind_of?(Array)
104
113
 
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Serializer
3
- VERSION = '0.6.1'
3
+ VERSION = '0.6.2'
4
4
  end
5
5
  end
@@ -33,7 +33,7 @@ describe RestPack::Serializer do
33
33
 
34
34
  class PersonSerializer
35
35
  include RestPack::Serializer
36
- attributes :id, :name, :description, :href, :admin_info
36
+ attributes :id, :name, :description, :href, :admin_info, :string_keys
37
37
 
38
38
  def description
39
39
  "This is person ##{id}"
@@ -41,9 +41,9 @@ describe RestPack::Serializer do
41
41
 
42
42
  def admin_info
43
43
  {
44
- "key" => "super_secret_sauce",
45
- "array" => [
46
- { "name" => "Alex" }
44
+ key: "super_secret_sauce",
45
+ array: [
46
+ { name: "Alex" }
47
47
  ]
48
48
  }
49
49
  end
@@ -52,6 +52,20 @@ describe RestPack::Serializer do
52
52
  @context[:is_admin?]
53
53
  end
54
54
 
55
+ def string_keys
56
+ {
57
+ "kid_b" => "Ben",
58
+ "likes" => {
59
+ "foods" => ["crackers", "stawberries"],
60
+ "books" => ["Dumpy", "That's Not My Tiger"]
61
+ }
62
+ }
63
+ end
64
+
65
+ def include_string_keys?
66
+ @context[:is_ben?]
67
+ end
68
+
55
69
  def custom_attributes
56
70
  {
57
71
  :custom_key => "custom value for model id #{@model.id}"
@@ -187,6 +201,22 @@ describe RestPack::Serializer do
187
201
  end
188
202
  end
189
203
  end
204
+
205
+ describe ".as_json_symbolized" do
206
+ it "symbolizes keys recursively" do
207
+ serializer.as_json_symbolized(person, { is_ben?: true }).should == {
208
+ id: '123', name: 'Gavin', description: 'This is person #123',
209
+ href: '/people/123', custom_key: 'custom value for model id 123',
210
+ string_keys: {
211
+ kid_b: "Ben",
212
+ likes: {
213
+ foods: ["crackers", "stawberries"],
214
+ books: ["Dumpy", "That's Not My Tiger"]
215
+ }
216
+ }
217
+ }
218
+ end
219
+ end
190
220
  end
191
221
 
192
222
  describe "#model_class" do
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.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport