restpack_serializer 0.4.17 → 0.4.18

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: 494cb0bfac15a84de1f7500683308a49b0469b57
4
- data.tar.gz: 502cb3b906015875838b200e384deff1c7b69d2c
3
+ metadata.gz: b5d4602dfd29b489ac3e1a2a1192625f5f599374
4
+ data.tar.gz: 5d9a645df308d563842d2a0441ae432dc7b77575
5
5
  SHA512:
6
- metadata.gz: efcc699c7d4ca5bc4e5f7d6220432bf566d513debd802e31cdae2e636af4236253b86a2b2713be20e2f3c5908140f2e9a06b4d5433e8c912b513a83519d3d47e
7
- data.tar.gz: 277b10f0c776d9a321492485c8ebfad60477b1ef91ab7581dc8ee9da247b4083b06a39b27bcaaba4a0af6ee24146fd53131859a75eaf02dbe5f2617c3b3afcad
6
+ metadata.gz: c71574252375b37bf0b2052a0c583d5eed1ce568682fe1a42ac767d253d4e5bdf38b66162d624d992d9b287f02fa157cf33322dd25408eadec50dbd6f84a5115
7
+ data.tar.gz: 561c9c63d41976b5b77111dc5301b33aa9e017cb9fe3b177ded3dc7ad5024d00acd3f54f3a6fa6f23ec150d460e467bcba40bb39a2481f17fe0683346f6c10d4
@@ -29,6 +29,10 @@ module RestPack
29
29
  class InvalidInclude < Exception; end
30
30
 
31
31
  def as_json(model, context = {})
32
+ if model.kind_of?(Array)
33
+ return model.map { |item| as_json(item, context) }
34
+ end
35
+
32
36
  @model, @context = model, context
33
37
 
34
38
  data = {}
@@ -74,6 +78,7 @@ module RestPack
74
78
 
75
79
  module ClassMethods
76
80
  attr_accessor :model_class, :key
81
+
77
82
  def as_json(model, context = {})
78
83
  new.as_json(model, context)
79
84
  end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Serializer
3
- VERSION = '0.4.17'
3
+ VERSION = '0.4.18'
4
4
  end
5
5
  end
@@ -69,6 +69,22 @@ describe RestPack::Serializer do
69
69
  }
70
70
  end
71
71
 
72
+ context "serializes an array" do
73
+ let(:people) { [person, person] }
74
+ it "results in a serialized array" do
75
+ serializer.as_json(people).should == [
76
+ {
77
+ id: '123', name: 'Gavin', description: 'This is person #123',
78
+ href: '/people/123', custom_key: 'custom value for model id 123'
79
+ },
80
+ {
81
+ id: '123', name: 'Gavin', description: 'This is person #123',
82
+ href: '/people/123', custom_key: 'custom value for model id 123'
83
+ }
84
+ ]
85
+ end
86
+ end
87
+
72
88
  context "with options" do
73
89
  it "excludes specified attributes" do
74
90
  serializer.as_json(person, { include_description?: false }).should == {
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.4.17
4
+ version: 0.4.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord