restpack_serializer 0.2.12 → 0.2.13

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: 5d32bb32927a51cf68e6f76910199fc343c1f545
4
- data.tar.gz: e531717bffc615184c588e1523fb461874a5b402
3
+ metadata.gz: 970e2e0de08591a08d4a42d5d5f36868d202d192
4
+ data.tar.gz: 0eabb7a4194eb635b8d3bafd0220a7a1bc69bbbd
5
5
  SHA512:
6
- metadata.gz: b7a53fd767fff3671ba6818ffbeab9a43cff08b27f6424e39e2427b7be65cde6be6402bb54cc703c593c2f4e60697ce9b89bac53912728892bbaa015eeea2a52
7
- data.tar.gz: 4c68c689127a698f04f82670f241188cb621ae38fb600631c337b5967620de9f361bdeb03a548418bbe9506ee04edf83d0c19adbc8fd6636cdb1f0ebd468f527
6
+ metadata.gz: 659bba0a2505a6bfd3df5fce582bf191df3d1e5dce18530f14391dfe77633a2002def8c510bd469352ac283557f411acbab65407b7b59d2f65e1ec8d2e89a273
7
+ data.tar.gz: 1b446fdec2911aaef03845865b9fa83daa0edf794e63e959039a919fb0d9d0726de1a72ba546ec5a45a95f4befa07461b20e853d70969c9587266c05a9b9c6fc
data/README.md CHANGED
@@ -154,7 +154,7 @@ Side-loading allows related resources to be optionally included in a single API
154
154
  class AlbumSerializer
155
155
  include RestPack::Serializer
156
156
  attributes :id, :title, :year, :artist_id, :href
157
-
157
+
158
158
  can_include :songs, :artists
159
159
  end
160
160
  ```
@@ -61,24 +61,17 @@ module RestPack
61
61
  end
62
62
 
63
63
  module ClassMethods
64
+ attr_accessor :model_class, :key
64
65
  def as_json(model, context = {})
65
66
  new.as_json(model, context)
66
67
  end
67
68
 
68
- def set_model_class(klass)
69
- @model_class_name = klass.to_s
70
- end
71
-
72
- def model_class_name
73
- @model_class_name || self.name.chomp('Serializer')
74
- end
75
-
76
69
  def model_class
77
- model_class_name.constantize
70
+ @model_class || self.name.chomp('Serializer').constantize
78
71
  end
79
72
 
80
73
  def key
81
- self.model_class.send(:table_name).to_sym
74
+ (@key || self.model_class.send(:table_name)).to_sym
82
75
  end
83
76
 
84
77
  end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Serializer
3
- VERSION = '0.2.12'
3
+ VERSION = '0.2.13'
4
4
  end
5
5
  end
@@ -90,12 +90,12 @@ describe RestPack::Serializer do
90
90
  end
91
91
  end
92
92
 
93
- describe "#model_class_name" do
94
- it "extractes the Model name from the Serializer name" do
95
- PersonSerializer.model_class_name.should == "Person"
93
+ describe "#model_class" do
94
+ it "extracts the Model name from the Serializer name" do
95
+ PersonSerializer.model_class.should == Person
96
96
  end
97
97
 
98
- context "with namespaced model class name" do
98
+ context "with namespaced model class" do
99
99
  module SomeNamespace
100
100
  class Model
101
101
  end
@@ -103,25 +103,29 @@ describe RestPack::Serializer do
103
103
 
104
104
  class NamespacedSerializer
105
105
  include RestPack::Serializer
106
- set_model_class SomeNamespace::Model
106
+ self.model_class = SomeNamespace::Model
107
107
  end
108
108
 
109
- it "return the correct class" do
110
- NamespacedSerializer.model_class_name.should == "SomeNamespace::Model"
109
+ it "returns the correct class" do
111
110
  NamespacedSerializer.model_class.should == SomeNamespace::Model
112
111
  end
113
112
  end
114
113
  end
115
114
 
116
- describe "#model_class" do
117
- it "returns the correct class" do
118
- PersonSerializer.model_class.should == Person
119
- end
120
- end
121
-
122
115
  describe "#key" do
123
116
  it "returns the correct key" do
124
117
  PersonSerializer.key.should == :people
125
118
  end
119
+
120
+ context "with custom key" do
121
+ class SerializerWithCustomKey
122
+ include RestPack::Serializer
123
+ self.key = :custom_key
124
+ end
125
+
126
+ it "returns the correct key" do
127
+ SerializerWithCustomKey.key.should == :custom_key
128
+ end
129
+ end
126
130
  end
127
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce