conglomerate 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/conglomerate.rb +1 -0
- data/lib/conglomerate/collection.rb +1 -0
- data/lib/conglomerate/command.rb +12 -0
- data/lib/conglomerate/serializer.rb +35 -2
- data/lib/conglomerate/tree_deserializer.rb +4 -2
- data/lib/conglomerate/version.rb +1 -1
- data/spec/collection_spec.rb +12 -0
- data/spec/command_spec.rb +30 -0
- data/spec/conglomerate_spec.rb +26 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c59715a987bfcf05b5005344ef0c1a72330193a9
|
4
|
+
data.tar.gz: 5fdd51b3702d7a807473064c048351ff411c73af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9255df416476d667a41e07d141aa613ae57704c59b798f501df9c61bb3d779e566ce0383d2a4eaae4c880ae99d84cf5a4284788e9a4db8b2ab4c7cac306eeb7
|
7
|
+
data.tar.gz: e40f478b4a9d83bc8bd697cba3c666608cd30e494a2855a5809a6440dda256fcf2c447e82a3258a172845afa0dad7100351ee3ec2db2a666d5a0117a24469248
|
data/README.md
CHANGED
@@ -48,6 +48,8 @@ class TeamSerializer
|
|
48
48
|
link :root { root_url }
|
49
49
|
|
50
50
|
query :search, :data => :id { search_teams_url }
|
51
|
+
|
52
|
+
command :populate, :data => :id { populate_teams_url }
|
51
53
|
end
|
52
54
|
|
53
55
|
# Step 2: Serialize any object
|
@@ -105,6 +107,15 @@ end
|
|
105
107
|
]
|
106
108
|
}
|
107
109
|
],
|
110
|
+
"commands": [
|
111
|
+
{
|
112
|
+
"rel": "populate",
|
113
|
+
"href": "http://example.com/teams/populate",
|
114
|
+
"data": [
|
115
|
+
{"name": "id", "value": ""}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
],
|
108
119
|
"template": {
|
109
120
|
"data": [
|
110
121
|
{"name": "name", "value": ""}
|
data/lib/conglomerate.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "conglomerate/datum"
|
|
8
8
|
require_relative "conglomerate/template"
|
9
9
|
require_relative "conglomerate/item"
|
10
10
|
require_relative "conglomerate/query"
|
11
|
+
require_relative "conglomerate/command"
|
11
12
|
require_relative "conglomerate/collection"
|
12
13
|
require_relative "conglomerate/tree_deserializer"
|
13
14
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Conglomerate
|
2
|
+
class Command
|
3
|
+
include Conglomerate::Particle
|
4
|
+
|
5
|
+
attribute :href, :type => String, :required => true
|
6
|
+
attribute :rel, :type => String, :required => true
|
7
|
+
attribute :name, :type => String
|
8
|
+
attribute :prompt, :type => String
|
9
|
+
|
10
|
+
array :data, :contains => Datum
|
11
|
+
end
|
12
|
+
end
|
@@ -22,7 +22,7 @@ module Conglomerate
|
|
22
22
|
attr_accessor :objects, :context
|
23
23
|
|
24
24
|
def actions
|
25
|
-
[:version, :href, :queries, :items, :template, :links]
|
25
|
+
[:version, :href, :queries, :commands, :items, :template, :links]
|
26
26
|
end
|
27
27
|
|
28
28
|
def apply_version(collection)
|
@@ -78,6 +78,20 @@ module Conglomerate
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
def apply_commands(collection)
|
82
|
+
commands = self.class._commands.map do |command|
|
83
|
+
build_command(
|
84
|
+
command[:rel], command[:data], command[:prompt], command[:block]
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
if commands.empty?
|
89
|
+
collection
|
90
|
+
else
|
91
|
+
collection.merge({"commands" => commands})
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
81
95
|
def apply_items(collection)
|
82
96
|
items = objects.map do |object|
|
83
97
|
item = {}
|
@@ -166,6 +180,13 @@ module Conglomerate
|
|
166
180
|
apply_data(query, :data => data, :default_value => "")
|
167
181
|
end
|
168
182
|
|
183
|
+
def build_command(rel, data, prompt, block)
|
184
|
+
command = {"rel" => rel.to_s}
|
185
|
+
command = apply_href(command, :proc => block)
|
186
|
+
command["prompt"] = prompt if prompt
|
187
|
+
apply_data(command, :data => data, :default_value => "")
|
188
|
+
end
|
189
|
+
|
169
190
|
def build_item_link(rel, proc: nil, object: nil)
|
170
191
|
link = {"rel" => rel.to_s}
|
171
192
|
apply_href(link, :proc => proc, :object => object)
|
@@ -229,6 +250,14 @@ module Conglomerate
|
|
229
250
|
}
|
230
251
|
end
|
231
252
|
|
253
|
+
def command(rel, data: [], prompt: nil, &block)
|
254
|
+
data = [*data]
|
255
|
+
data = data.map { |datum| {:name => datum} }
|
256
|
+
self._commands = self._commands << {
|
257
|
+
:rel => rel, :data => data, :prompt => prompt, :block => block
|
258
|
+
}
|
259
|
+
end
|
260
|
+
|
232
261
|
def attribute(
|
233
262
|
name, template: false, rel: nil, type: :value, prompt: nil, &block
|
234
263
|
)
|
@@ -257,7 +286,7 @@ module Conglomerate
|
|
257
286
|
end
|
258
287
|
|
259
288
|
attr_writer :_href, :_item_href, :_queries, :_attributes, :_links,
|
260
|
-
:_item_links, :_templates
|
289
|
+
:_item_links, :_templates, :_commands
|
261
290
|
|
262
291
|
def _href
|
263
292
|
@_href || nil
|
@@ -271,6 +300,10 @@ module Conglomerate
|
|
271
300
|
@_queries || []
|
272
301
|
end
|
273
302
|
|
303
|
+
def _commands
|
304
|
+
@_commands || []
|
305
|
+
end
|
306
|
+
|
274
307
|
def _attributes
|
275
308
|
@_attributes || []
|
276
309
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Conglomerate
|
2
2
|
class TreeDeserializer
|
3
|
-
PARTICLES = [
|
3
|
+
PARTICLES = [
|
4
|
+
Collection, Item, Error, Template, Datum, Query, Command, Item
|
5
|
+
]
|
4
6
|
|
5
7
|
def initialize(object)
|
6
8
|
self.object = object
|
@@ -26,7 +28,7 @@ module Conglomerate
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
|
31
|
+
klass.new(attributes)
|
30
32
|
end
|
31
33
|
|
32
34
|
def deserialize_attribute(attribute, attr_metadata)
|
data/lib/conglomerate/version.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -37,4 +37,16 @@ describe Conglomerate::Collection do
|
|
37
37
|
expect(Conglomerate.serialize(collection)["queries"]).to include(Conglomerate.serialize(query))
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
context "commands" do
|
42
|
+
it "serializes commands correctly" do
|
43
|
+
command = Conglomerate::Command.new(
|
44
|
+
:href => "http://this.is.a.command",
|
45
|
+
:rel => "Something"
|
46
|
+
)
|
47
|
+
|
48
|
+
collection.commands << command
|
49
|
+
expect(Conglomerate.serialize(collection)["commands"]).to include(Conglomerate.serialize(command))
|
50
|
+
end
|
51
|
+
end
|
40
52
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
require_relative "../lib/conglomerate"
|
3
|
+
|
4
|
+
describe Conglomerate::Command do
|
5
|
+
let(:command) {
|
6
|
+
Conglomerate::Command.new(
|
7
|
+
:href => "http://this.is.a.command/",
|
8
|
+
:rel => "some_command"
|
9
|
+
)
|
10
|
+
}
|
11
|
+
|
12
|
+
context "required attributes" do
|
13
|
+
specify "href" do
|
14
|
+
expect { Conglomerate::Command.new(:rel => "") }.to raise_error("MissingAttribute")
|
15
|
+
end
|
16
|
+
|
17
|
+
specify "rel" do
|
18
|
+
expect { Conglomerate::Command.new(:href => "") }.to raise_error("MissingAttribute")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "data" do
|
23
|
+
it "serializes properly" do
|
24
|
+
datum = Conglomerate::Datum.new(:name => "name")
|
25
|
+
|
26
|
+
command.data << datum
|
27
|
+
expect(Conglomerate.serialize(command)["data"]).to include(Conglomerate.serialize(datum))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/conglomerate_spec.rb
CHANGED
@@ -34,6 +34,10 @@ class ConglomerateTestSerializer
|
|
34
34
|
search_items_url
|
35
35
|
end
|
36
36
|
|
37
|
+
command :populate, :data => :id, :prompt => "test 123" do
|
38
|
+
populate_items_url
|
39
|
+
end
|
40
|
+
|
37
41
|
template :repeats, :prompt => "true|false"
|
38
42
|
end
|
39
43
|
|
@@ -70,6 +74,7 @@ describe Conglomerate do
|
|
70
74
|
"Context",
|
71
75
|
:request => request,
|
72
76
|
:search_items_url => "https://example.com/items/search",
|
77
|
+
:populate_items_url => "https://example.com/items/populate",
|
73
78
|
).tap do |context|
|
74
79
|
allow(context).to receive(:item_url).with(1) {
|
75
80
|
"https://example.com/items/1"
|
@@ -145,6 +150,27 @@ describe Conglomerate do
|
|
145
150
|
end
|
146
151
|
end
|
147
152
|
|
153
|
+
describe "#command" do
|
154
|
+
it "doesn't include any command templates if none are provided" do
|
155
|
+
expect(null_collection.keys).to_not include("commands")
|
156
|
+
end
|
157
|
+
|
158
|
+
it "adds a command template to the collection" do
|
159
|
+
expect(test_collection["commands"]).to match_array(
|
160
|
+
[
|
161
|
+
{
|
162
|
+
"href" => "https://example.com/items/populate",
|
163
|
+
"rel" => "populate",
|
164
|
+
"prompt" => "test 123",
|
165
|
+
"data" => [
|
166
|
+
{"name" => "id", "value" => ""}
|
167
|
+
]
|
168
|
+
}
|
169
|
+
]
|
170
|
+
)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
148
174
|
describe "#attribute(s)" do
|
149
175
|
context "items" do
|
150
176
|
it "skips items if there are no attributes" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conglomerate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/conglomerate.rb
|
70
70
|
- lib/conglomerate/array.rb
|
71
71
|
- lib/conglomerate/collection.rb
|
72
|
+
- lib/conglomerate/command.rb
|
72
73
|
- lib/conglomerate/datum.rb
|
73
74
|
- lib/conglomerate/error.rb
|
74
75
|
- lib/conglomerate/item.rb
|
@@ -82,6 +83,7 @@ files:
|
|
82
83
|
- lib/conglomerate/tree_serializer.rb
|
83
84
|
- lib/conglomerate/version.rb
|
84
85
|
- spec/collection_spec.rb
|
86
|
+
- spec/command_spec.rb
|
85
87
|
- spec/conglomerate_spec.rb
|
86
88
|
- spec/datum_spec.rb
|
87
89
|
- spec/link_spec.rb
|
@@ -115,6 +117,7 @@ specification_version: 4
|
|
115
117
|
summary: A library to serialize Ruby objects into collection+json
|
116
118
|
test_files:
|
117
119
|
- spec/collection_spec.rb
|
120
|
+
- spec/command_spec.rb
|
118
121
|
- spec/conglomerate_spec.rb
|
119
122
|
- spec/datum_spec.rb
|
120
123
|
- spec/link_spec.rb
|