conglomerate 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/conglomerate/serializer.rb +13 -2
- data/lib/conglomerate/version.rb +1 -1
- data/spec/conglomerate_spec.rb +7 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff30998d5c96dd7899c51a61714276433c03fbcf
|
4
|
+
data.tar.gz: 77853ae3ece6ad3a195617acbdd6a7d5fd928f53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00690b70700b303ff36cc1685530ac273c1867b4bec6e5e9c74ef00122a2700e930fd02e5f25af79ae3c7e41bc0f64b4b67d79c59f0d77b0959a3e84924efce1
|
7
|
+
data.tar.gz: 839679dd34e8bd09a179574000c7b56bc90ba8b11bdcb36cbb0511cf615706523bff82cfc67c5c104a1db7a84742ccdba626547aab7cbae43660971b364b91fe
|
@@ -92,6 +92,7 @@ module Conglomerate
|
|
92
92
|
|
93
93
|
links = self.class._attributes
|
94
94
|
.select { |attr| attr[:block] }
|
95
|
+
links += self.class._item_links
|
95
96
|
|
96
97
|
if links.empty?
|
97
98
|
item.empty? ? nil : item
|
@@ -128,7 +129,7 @@ module Conglomerate
|
|
128
129
|
def apply_links(collection, links: self.class._links, object: nil)
|
129
130
|
if object && !links.empty?
|
130
131
|
links = links.map do |link|
|
131
|
-
if present?(object.send(link[:name]))
|
132
|
+
if !link.has_key?(:name) || present?(object.send(link[:name]))
|
132
133
|
build_item_link(
|
133
134
|
link[:rel], :proc => link[:block], :object => object
|
134
135
|
)
|
@@ -231,6 +232,12 @@ module Conglomerate
|
|
231
232
|
}
|
232
233
|
end
|
233
234
|
|
235
|
+
def item_link(rel, &block)
|
236
|
+
self._item_links = self._item_links << {
|
237
|
+
:rel => rel, :block => block
|
238
|
+
}
|
239
|
+
end
|
240
|
+
|
234
241
|
def template(name, type: :value, prompt: nil)
|
235
242
|
self._templates = self._templates << {
|
236
243
|
:name => name, :type => type, :prompt => prompt, :template => true
|
@@ -238,7 +245,7 @@ module Conglomerate
|
|
238
245
|
end
|
239
246
|
|
240
247
|
attr_writer :_href, :_item_href, :_queries, :_attributes, :_links,
|
241
|
-
:_templates
|
248
|
+
:_item_links, :_templates
|
242
249
|
|
243
250
|
def _href
|
244
251
|
@_href || nil
|
@@ -260,6 +267,10 @@ module Conglomerate
|
|
260
267
|
@_links || []
|
261
268
|
end
|
262
269
|
|
270
|
+
def _item_links
|
271
|
+
@_item_links || []
|
272
|
+
end
|
273
|
+
|
263
274
|
def _templates
|
264
275
|
@_templates || []
|
265
276
|
end
|
data/lib/conglomerate/version.rb
CHANGED
data/spec/conglomerate_spec.rb
CHANGED
@@ -18,8 +18,8 @@ class ConglomerateTestSerializer
|
|
18
18
|
attribute :team_ids, :rel => :teams, :type => :array do |item|
|
19
19
|
team_url(item.team_ids.join(","))
|
20
20
|
end
|
21
|
-
|
22
|
-
|
21
|
+
item_link :users do |item|
|
22
|
+
users_search_url :object_id => item.id
|
23
23
|
end
|
24
24
|
attribute :is_available
|
25
25
|
|
@@ -78,6 +78,9 @@ describe Conglomerate do
|
|
78
78
|
"https://example.com/teams/1,2"
|
79
79
|
}
|
80
80
|
allow(context).to receive(:test_url) { "abc" }
|
81
|
+
allow(context).to receive(:users_search_url).with(:object_id => 1) {
|
82
|
+
"def"
|
83
|
+
}
|
81
84
|
end
|
82
85
|
end
|
83
86
|
|
@@ -161,12 +164,12 @@ describe Conglomerate do
|
|
161
164
|
{"name" => "event_id", "value" => 2},
|
162
165
|
{"name" => "roster_id", "value" => nil},
|
163
166
|
{"name" => "team_ids", "array" => [1,2]},
|
164
|
-
{"name" => "user_ids", "array" => []},
|
165
167
|
{"name" => "is_available", "value" => false}
|
166
168
|
],
|
167
169
|
"links" => [
|
168
170
|
{"rel" => "event", "href" => "https://example.com/events/2"},
|
169
|
-
{"rel" => "teams", "href" => "https://example.com/teams/1,2"}
|
171
|
+
{"rel" => "teams", "href" => "https://example.com/teams/1,2"},
|
172
|
+
{"rel" => "users", "href" => "def"}
|
170
173
|
]
|
171
174
|
}
|
172
175
|
]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conglomerate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|