encore 0.2 → 0.2.1

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: 663990f322867daf2d604b90b17d6f041c5efc38
4
- data.tar.gz: ea1a8ac943113bad1c8f1d8134221277ce869b77
3
+ metadata.gz: 67ae9330944ea710370dd8ea1032b1a7b47267dd
4
+ data.tar.gz: 5a6156f14a3d3c1d753b6d5e9ce31ca8a365b6e3
5
5
  SHA512:
6
- metadata.gz: 3ec3e4388cc983e2de0d9c418998d9840db145c4bd89103a087272a2d4429a7661087849d2d1ded571b7c1d8b43a817f6b7fa830070b9abbb03fc74d6f454ac2
7
- data.tar.gz: 69b5beb8f26e43a18fead232548f9681a292e49887eb36882a0a2d018b716d8ce59126fb9155313c152f80c01c2af91484b1ee0e6538ee8db2708d4f08da985c
6
+ metadata.gz: e4c6e0c8c5e7868808950430b841eee3a5bf6390491eadd41d96910399a01aed48d8436bec65871da3bcf10481b6440ab4d18daffdcb98071b07a045da9b2344
7
+ data.tar.gz: d4a85a515aec1882439173b62004239fe8e0adcfafde0f0bde7d49b801f813839f9f469f52987c40e11cee1d87a6691074b63f443f227efb249a1b1d06a9759c
data/README.md CHANGED
@@ -45,9 +45,7 @@ class PostSerializer < Encore::Serializer::Base
45
45
  # By default, root_key will be the pluralized model
46
46
  # name. If you want to set a custom root_key, you can
47
47
  # do that:
48
- def self.root_key
49
- :blog_posts
50
- end
48
+ root_key :blog_posts
51
49
  end
52
50
  ```
53
51
 
@@ -118,9 +116,7 @@ Since we don’t want all associations to be exposed, we also need to allow the
118
116
  class PostSerializer < Encore::Serializer::Base
119
117
  # ...
120
118
 
121
- def self.can_include
122
- [:author, :comments]
123
- end
119
+ can_include :author, :comments
124
120
  end
125
121
  ```
126
122
 
@@ -167,9 +163,7 @@ If you want the `comments` to **always** be included when you request a `post`,
167
163
  class PostSerializer < Encore::Serializer::Base
168
164
  # ...
169
165
 
170
- def self.always_include
171
- [:comments]
172
- end
166
+ always_include :comments
173
167
  end
174
168
  ```
175
169
 
@@ -23,27 +23,47 @@ module Encore
23
23
  end
24
24
 
25
25
  # Specify which resources the API can be included in the "linked" top-level key.
26
- def self.can_include
27
- []
26
+ def self.can_include(*value)
27
+ if value.any?
28
+ @can_include = value.flatten
29
+ else
30
+ @can_include ||= []
31
+ end
28
32
  end
29
33
 
30
34
  # Specify which resources the API always include in the "linked" top-level key.
31
- def self.always_include
32
- []
35
+ def self.always_include(*value)
36
+ if value.any?
37
+ @always_include = value.flatten
38
+ else
39
+ @always_include ||= []
40
+ end
33
41
  end
34
42
 
35
43
  # Specify which resources the API exposes URL to.
36
44
  # Default is can_include + always_include.
37
- def self.can_access
38
- can_include | always_include
45
+ def self.can_access(*value)
46
+ if value.any?
47
+ @can_access = value.flatten
48
+ else
49
+ @can_access ||= can_include | always_include
50
+ end
39
51
  end
40
52
 
41
- def self.root_key
42
- model_class.name.pluralize.underscore.to_sym
53
+ def self.root_key(value = nil)
54
+ if value
55
+ @root_key = value
56
+ else
57
+ @root_key ||= model_class.name.pluralize.underscore.to_sym
58
+ end
43
59
  end
44
60
 
45
- def self.key_mappings
46
- {}
61
+ def self.key_mappings(value = nil)
62
+ if value
63
+ @key_mappings = value
64
+ else
65
+ @key_mappings ||= {}
66
+ end
47
67
  end
48
68
  end
49
69
  end
@@ -8,7 +8,6 @@ module Encore
8
8
  def self.add(linked_ids, object)
9
9
  included_models = linked_ids.keys.map { |key| key.downcase }
10
10
  included_models << object.klass.name.downcase
11
- included_models << object.klass.name.downcase.pluralize
12
11
 
13
12
  linked_ids.reduce({}) do |memo, (model, ids)|
14
13
  klass = model.constantize
@@ -1,3 +1,3 @@
1
1
  module Encore
2
- VERSION = '0.2'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -22,9 +22,7 @@ describe Encore::Persister do
22
22
  :name
23
23
  end
24
24
 
25
- def key_mappings
26
- { snake_case_key: :name }
27
- end
25
+ key_mappings snake_case_key: :name
28
26
  end
29
27
  end
30
28
 
@@ -58,9 +58,7 @@ describe Encore::Serializer do
58
58
  spawn_serializer('UserSerializer') do
59
59
  attributes :name
60
60
 
61
- def always_include
62
- %i(project)
63
- end
61
+ always_include :project
64
62
  end
65
63
  end
66
64
 
@@ -74,9 +72,7 @@ describe Encore::Serializer do
74
72
  spawn_serializer('UserSerializer') do
75
73
  attributes :name
76
74
 
77
- def always_include
78
- %i(project)
79
- end
75
+ always_include :project
80
76
  end
81
77
  end
82
78
 
@@ -58,9 +58,7 @@ describe Encore::Serializer do
58
58
  spawn_serializer('UserSerializer') do
59
59
  attributes :name
60
60
 
61
- def can_include
62
- %i(project)
63
- end
61
+ can_include :project
64
62
  end
65
63
  end
66
64
 
@@ -26,16 +26,12 @@ describe Encore::Serializer do
26
26
  spawn_serializer('ProjectSerializer') do
27
27
  attributes :name
28
28
 
29
- def can_include
30
- %i(user users)
31
- end
29
+ can_include :user, :users
32
30
  end
33
31
  spawn_serializer('UserSerializer') do
34
32
  attributes :name
35
33
 
36
- def can_include
37
- %i(project)
38
- end
34
+ can_include :project
39
35
  end
40
36
  end
41
37
 
@@ -33,23 +33,17 @@ describe Encore::Serializer do
33
33
  spawn_serializer('ProjectSerializer') do
34
34
  attributes :name
35
35
 
36
- def can_include
37
- %i(organization user users)
38
- end
36
+ can_include :organization, :user, :users
39
37
  end
40
38
  spawn_serializer('UserSerializer') do
41
39
  attributes :name
42
40
 
43
- def can_include
44
- %i(project)
45
- end
41
+ can_include :project
46
42
  end
47
43
  spawn_serializer('OrganizationSerializer') do
48
44
  attributes :name
49
45
 
50
- def can_include
51
- %i(projects)
52
- end
46
+ can_include :projects
53
47
  end
54
48
  end
55
49
 
@@ -77,8 +71,8 @@ describe Encore::Serializer do
77
71
  end
78
72
 
79
73
  context 'already included resource' do
80
- it { expect(serialized[:linked][:projects][0][:links][:users]).to eq([user1.id.to_s]) }
81
- it { expect(serialized[:linked][:projects][1][:links][:users]).to eq([user2.id.to_s]) }
74
+ it { expect(serialized[:linked][:projects][0][:links][:users]).to eq({ href: '/users?project_id=1', type: 'users' }) }
75
+ it { expect(serialized[:linked][:projects][1][:links][:users]).to eq({ href: '/users?project_id=2', type: 'users' }) }
82
76
  end
83
77
 
84
78
  context 'not included resource' do
@@ -33,23 +33,17 @@ describe Encore::Serializer do
33
33
  spawn_serializer('ProjectSerializer') do
34
34
  attributes :name
35
35
 
36
- def can_include
37
- %i(organization user users)
38
- end
36
+ can_include :organization, :user, :users
39
37
  end
40
38
  spawn_serializer('UserSerializer') do
41
39
  attributes :name
42
40
 
43
- def can_include
44
- %i(project)
45
- end
41
+ can_include :project
46
42
  end
47
43
  spawn_serializer('OrganizationSerializer') do
48
44
  attributes :name
49
45
 
50
- def can_include
51
- %i(projects)
52
- end
46
+ can_include :projects
53
47
  end
54
48
  end
55
49
 
@@ -34,9 +34,7 @@ describe Encore::Serializer do
34
34
  spawn_serializer('UserSerializer') do
35
35
  attributes :name, :links
36
36
 
37
- def can_include
38
- %i(project)
39
- end
37
+ can_include :project
40
38
  end
41
39
  spawn_model('Project') do
42
40
  has_many :users
@@ -64,9 +62,7 @@ describe Encore::Serializer do
64
62
  spawn_serializer('UserSerializer') do
65
63
  attributes :name, :links
66
64
 
67
- def can_include
68
- %i(project)
69
- end
65
+ can_include :project
70
66
  end
71
67
  spawn_model('Project') do
72
68
  has_many :users
@@ -94,13 +90,9 @@ describe Encore::Serializer do
94
90
  spawn_serializer('UserSerializer') do
95
91
  attributes :name, :links
96
92
 
97
- def can_include
98
- %i(project)
99
- end
93
+ can_include :project
100
94
 
101
- def can_access
102
- []
103
- end
95
+ can_access []
104
96
  end
105
97
  spawn_model('Project') do
106
98
  has_many :users
@@ -128,13 +120,9 @@ describe Encore::Serializer do
128
120
  spawn_serializer('UserSerializer') do
129
121
  attributes :name, :links
130
122
 
131
- def can_include
132
- %i(project)
133
- end
123
+ can_include :project
134
124
 
135
- def can_access
136
- []
137
- end
125
+ can_access []
138
126
  end
139
127
  spawn_model('Project') do
140
128
  has_many :users
@@ -162,9 +150,7 @@ describe Encore::Serializer do
162
150
  spawn_serializer('UserSerializer') do
163
151
  attributes :name, :links
164
152
 
165
- def can_include
166
- %i(project)
167
- end
153
+ can_include :project
168
154
  end
169
155
  spawn_model('Project') do
170
156
  has_many :users
@@ -208,9 +194,7 @@ describe Encore::Serializer do
208
194
  spawn_serializer('UserSerializer') do
209
195
  attributes :name, :links
210
196
 
211
- def can_include
212
- %i(projects)
213
- end
197
+ can_include :projects
214
198
  end
215
199
  spawn_model('Project') do
216
200
  belongs_to :user
@@ -255,9 +239,7 @@ describe Encore::Serializer do
255
239
  spawn_serializer('UserSerializer') do
256
240
  attributes :name, :links
257
241
 
258
- def can_include
259
- %i(project)
260
- end
242
+ can_include :project
261
243
  end
262
244
  spawn_model('Project')
263
245
  spawn_serializer('ProjectSerializer') do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encore
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel