conglomerate 0.3.1 → 0.4.0
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 +4 -4
- data/lib/conglomerate/serializer.rb +30 -6
- data/lib/conglomerate/version.rb +1 -1
- data/spec/conglomerate_spec.rb +5 -2
- 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: cf07bfe4f1b76114a12c761021963d757b4863aa
|
4
|
+
data.tar.gz: 9adfde6792cb55ce176fa093121730dd0a14c3f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68c902816e927e2e82dce10629dd2f8e21970c46bffb505dc9d5224148c8ccf36c3de41c6eac81226c9dee4289e3ae9cf7a3aeed2c21bda15e3b458cabc7d869
|
7
|
+
data.tar.gz: 65ecf817f7af2e06b3ef34cfca4abe80a698a8ff84d3b1e713d9214795edb9d1c8d4025e985689970d1b2b08333c1ddab4fc30da2ec42ec6e3129d50441941f6
|
@@ -41,15 +41,21 @@ module Conglomerate
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def apply_data(
|
44
|
+
def apply_data(
|
45
|
+
collection, data: [], object: nil, default_value: nil,
|
46
|
+
build_template: false
|
47
|
+
)
|
45
48
|
data = data.map do |datum|
|
46
49
|
name = datum[:name]
|
47
50
|
type = datum.fetch(:type, :value)
|
51
|
+
prompt = datum.fetch(:prompt, nil)
|
48
52
|
value = sanitize_value(
|
49
53
|
object, :name => name, :type => type, :default_value => default_value
|
50
54
|
)
|
51
55
|
|
52
|
-
{"name" => name.to_s, type.to_s => value}
|
56
|
+
{"name" => name.to_s, type.to_s => value}.tap do |d|
|
57
|
+
d["prompt"] = prompt if build_template && prompt
|
58
|
+
end
|
53
59
|
end
|
54
60
|
|
55
61
|
if data.empty?
|
@@ -104,12 +110,17 @@ module Conglomerate
|
|
104
110
|
def apply_template(collection)
|
105
111
|
attrs = self.class._attributes
|
106
112
|
.select { |attr| attr[:template] }
|
113
|
+
attrs += self.class._templates
|
107
114
|
|
108
115
|
if attrs.empty?
|
109
116
|
collection
|
110
117
|
else
|
111
118
|
collection.merge(
|
112
|
-
{
|
119
|
+
{
|
120
|
+
"template" => apply_data(
|
121
|
+
{}, :data => attrs, :default_value => "", :build_template => true
|
122
|
+
)
|
123
|
+
}
|
113
124
|
)
|
114
125
|
end
|
115
126
|
end
|
@@ -201,10 +212,12 @@ module Conglomerate
|
|
201
212
|
}
|
202
213
|
end
|
203
214
|
|
204
|
-
def attribute(
|
215
|
+
def attribute(
|
216
|
+
name, template: false, rel: nil, type: :value, prompt: nil, &block
|
217
|
+
)
|
205
218
|
self._attributes = self._attributes << {
|
206
219
|
:name => name, :template => template, :rel => rel, :type => type,
|
207
|
-
:block => block
|
220
|
+
:prompt => prompt, :block => block
|
208
221
|
}
|
209
222
|
end
|
210
223
|
|
@@ -214,7 +227,14 @@ module Conglomerate
|
|
214
227
|
}
|
215
228
|
end
|
216
229
|
|
217
|
-
|
230
|
+
def template(name, type: :value, prompt: nil)
|
231
|
+
self._templates = self._templates << {
|
232
|
+
:name => name, :type => type, :prompt => prompt, :template => true
|
233
|
+
}
|
234
|
+
end
|
235
|
+
|
236
|
+
attr_writer :_href, :_item_href, :_queries, :_attributes, :_links,
|
237
|
+
:_templates
|
218
238
|
|
219
239
|
def _href
|
220
240
|
@_href || nil
|
@@ -235,6 +255,10 @@ module Conglomerate
|
|
235
255
|
def _links
|
236
256
|
@_links || []
|
237
257
|
end
|
258
|
+
|
259
|
+
def _templates
|
260
|
+
@_templates || []
|
261
|
+
end
|
238
262
|
end
|
239
263
|
end
|
240
264
|
end
|
data/lib/conglomerate/version.rb
CHANGED
data/spec/conglomerate_spec.rb
CHANGED
@@ -7,7 +7,7 @@ class ConglomerateTestSerializer
|
|
7
7
|
href { test_url }
|
8
8
|
item_href { |item| item_url(item.id) }
|
9
9
|
|
10
|
-
attribute :description, :template => true
|
10
|
+
attribute :description, :template => true, :prompt => "awesome"
|
11
11
|
attribute :id
|
12
12
|
attribute :event_id, :rel => :event do |item|
|
13
13
|
event_url(item.event_id)
|
@@ -29,6 +29,8 @@ class ConglomerateTestSerializer
|
|
29
29
|
query :search, :data => :id do
|
30
30
|
search_items_url
|
31
31
|
end
|
32
|
+
|
33
|
+
template :repeats, :prompt => "true|false"
|
32
34
|
end
|
33
35
|
|
34
36
|
class ConglomerateExtraTestSerializer
|
@@ -189,7 +191,8 @@ describe Conglomerate do
|
|
189
191
|
it "includes a valid template if attributes have them" do
|
190
192
|
expect(test_collection["template"]["data"]).to match_array(
|
191
193
|
[
|
192
|
-
{"name" => "description", "value" => ""}
|
194
|
+
{"name" => "description", "value" => "", "prompt" => "awesome"},
|
195
|
+
{"name" => "repeats", "value" => "", "prompt" => "true|false"}
|
193
196
|
]
|
194
197
|
)
|
195
198
|
end
|
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.4.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-01-
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|