restpack_serializer 0.4.26 → 0.4.27
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d11e2c868b50066fc5b49f6b8d29e168faf2b796
|
4
|
+
data.tar.gz: 00041f1def3a304b8ba4abbcebda28cd509b0f78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1594047af58178562a684999fb18b5cb5089f334e741fa78572e6847e93248125fcad82a90f373dfba596264bc0f1023ec7c8dd9d27f91477fa0c454e200b5f3
|
7
|
+
data.tar.gz: cf12374078885eb07db598c0a1d20c9c767a5e229becde7e9fab503e8851def1a4d2fd43378514b3166c5e50b620ab5c389857c80ae8b19b912125dfde103346
|
@@ -7,7 +7,7 @@ class RestPack::Serializer::Factory
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def self.classify(identifier)
|
10
|
-
normalised_identifier = identifier.to_s.
|
10
|
+
normalised_identifier = identifier.to_s.underscore
|
11
11
|
[normalised_identifier, normalised_identifier.singularize].each do |format|
|
12
12
|
klass = RestPack::Serializer.class_map[format]
|
13
13
|
return klass.new if klass
|
@@ -16,9 +16,9 @@ module RestPack
|
|
16
16
|
@@class_map ||= {}
|
17
17
|
|
18
18
|
included do
|
19
|
-
identifier = self.to_s.
|
19
|
+
identifier = self.to_s.underscore.chomp('_serializer')
|
20
20
|
@@class_map[identifier] = self
|
21
|
-
@@class_map[identifier.split('
|
21
|
+
@@class_map[identifier.split('/').last] = self
|
22
22
|
end
|
23
23
|
|
24
24
|
include RestPack::Serializer::Paging
|
@@ -3,26 +3,47 @@ require 'spec_helper'
|
|
3
3
|
describe RestPack::Serializer::Factory do
|
4
4
|
let(:factory) { RestPack::Serializer::Factory }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
describe "single-word" do
|
7
|
+
it "creates by string" do
|
8
|
+
factory.create("Song").should be_an_instance_of(MyApp::SongSerializer)
|
9
|
+
end
|
10
|
+
it "creates by lowercase string" do
|
11
|
+
factory.create("song").should be_an_instance_of(MyApp::SongSerializer)
|
12
|
+
end
|
13
|
+
it "creates by lowercase plural string" do
|
14
|
+
factory.create("songs").should be_an_instance_of(MyApp::SongSerializer)
|
15
|
+
end
|
16
|
+
it "creates by symbol" do
|
17
|
+
factory.create(:song).should be_an_instance_of(MyApp::SongSerializer)
|
18
|
+
end
|
19
|
+
it "creates by class" do
|
20
|
+
factory.create(MyApp::Song).should be_an_instance_of(MyApp::SongSerializer)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "creates multiple with Array" do
|
24
|
+
serializers = factory.create("Song", "artists", :album)
|
25
|
+
serializers[0].should be_an_instance_of(MyApp::SongSerializer)
|
26
|
+
serializers[1].should be_an_instance_of(MyApp::ArtistSerializer)
|
27
|
+
serializers[2].should be_an_instance_of(MyApp::AlbumSerializer)
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
describe "multi-word" do
|
32
|
+
it "creates multi-word string" do
|
33
|
+
factory.create("AlbumReview").should be_an_instance_of(MyApp::AlbumReviewSerializer)
|
34
|
+
end
|
35
|
+
it "creates multi-word lowercase string" do
|
36
|
+
factory.create("album_review").should be_an_instance_of(MyApp::AlbumReviewSerializer)
|
37
|
+
end
|
38
|
+
it "creates multi-word lowercase plural string" do
|
39
|
+
factory.create("album_reviews").should be_an_instance_of(MyApp::AlbumReviewSerializer)
|
40
|
+
end
|
41
|
+
it "creates multi-word symbol" do
|
42
|
+
factory.create(:album_review).should be_an_instance_of(MyApp::AlbumReviewSerializer)
|
43
|
+
end
|
44
|
+
it "creates multi-word class" do
|
45
|
+
factory.create(MyApp::AlbumReview).should be_an_instance_of(MyApp::AlbumReviewSerializer)
|
46
|
+
end
|
27
47
|
end
|
48
|
+
|
28
49
|
end
|
data/spec/fixtures/db.rb
CHANGED
@@ -23,6 +23,13 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
23
23
|
t.datetime "updated_at"
|
24
24
|
end
|
25
25
|
|
26
|
+
create_table "album_reviews", :force => true do |t|
|
27
|
+
t.string "message"
|
28
|
+
t.integer "album_id"
|
29
|
+
t.datetime "created_at"
|
30
|
+
t.datetime "updated_at"
|
31
|
+
end
|
32
|
+
|
26
33
|
create_table "songs", :force => true do |t|
|
27
34
|
t.string "title"
|
28
35
|
t.integer "album_id"
|
@@ -54,6 +61,12 @@ module MyApp
|
|
54
61
|
|
55
62
|
belongs_to :artist
|
56
63
|
has_many :songs
|
64
|
+
has_many :album_reviews
|
65
|
+
end
|
66
|
+
|
67
|
+
class AlbumReview < ActiveRecord::Base
|
68
|
+
attr_accessible :message
|
69
|
+
belongs_to :album
|
57
70
|
end
|
58
71
|
|
59
72
|
class Song < ActiveRecord::Base
|
@@ -18,6 +18,12 @@ module MyApp
|
|
18
18
|
can_filter_by :year
|
19
19
|
end
|
20
20
|
|
21
|
+
class AlbumReviewSerializer
|
22
|
+
include RestPack::Serializer
|
23
|
+
attributes :message
|
24
|
+
can_filter_by :album
|
25
|
+
end
|
26
|
+
|
21
27
|
class ArtistSerializer
|
22
28
|
include RestPack::Serializer
|
23
29
|
attributes :id, :name, :website
|
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.
|
4
|
+
version: 0.4.27
|
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-06-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|