conglomerate 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/conglomerate/serializer.rb +13 -8
- data/lib/conglomerate/version.rb +1 -1
- data/spec/conglomerate_spec.rb +2 -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: 9da3788aca18b7373349738518eb060890f2bc0b
|
4
|
+
data.tar.gz: 13ce8616d35fa4e79621b924bc58d3444cbd0fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82efadf83f9b16cb46617c81995e7e5b1df6e9706c08406aa0c33e0a2d45b9a10cb5fe2bfca3d62606409743da4ce329b1869ccf53f4cb0dd2e35f12673832c
|
7
|
+
data.tar.gz: 2647c169ae848cc2a0bfdd319b35e1dd2db0c30a2929ee1107f0a7e9bb9dec3b480fb35a9f8c63a740bb584859bf14ccd5fd25fc320659b7dacf3dbaaf0c1d53
|
data/Gemfile
CHANGED
@@ -42,8 +42,11 @@ module Conglomerate
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def apply_data(collection, data: [], object: nil)
|
45
|
-
data = data.map do |
|
46
|
-
|
45
|
+
data = data.map do |datum|
|
46
|
+
name = datum[:name]
|
47
|
+
value = object.nil? ? "" : object.send(name)
|
48
|
+
|
49
|
+
{"name" => name.to_s, datum.fetch(:type, "value").to_s => value}
|
47
50
|
end
|
48
51
|
|
49
52
|
if data.empty?
|
@@ -75,8 +78,8 @@ module Conglomerate
|
|
75
78
|
)
|
76
79
|
end
|
77
80
|
|
78
|
-
|
79
|
-
item = apply_data(item, :data =>
|
81
|
+
attributes = self.class._attributes
|
82
|
+
item = apply_data(item, :data => attributes, :object => object)
|
80
83
|
|
81
84
|
links = self.class._attributes
|
82
85
|
.select { |attr| attr[:block] }
|
@@ -98,7 +101,6 @@ module Conglomerate
|
|
98
101
|
def apply_template(collection)
|
99
102
|
attrs = self.class._attributes
|
100
103
|
.select { |attr| attr[:template] }
|
101
|
-
.map { |attr| attr[:name] }
|
102
104
|
|
103
105
|
if attrs.empty?
|
104
106
|
collection
|
@@ -173,14 +175,17 @@ module Conglomerate
|
|
173
175
|
end
|
174
176
|
|
175
177
|
def query(rel, data: [], &block)
|
178
|
+
data = [*data]
|
179
|
+
data = data.map { |datum| {:name => datum} }
|
176
180
|
self._queries = self._queries << {
|
177
|
-
:rel => rel, :data =>
|
181
|
+
:rel => rel, :data => data, :block => block
|
178
182
|
}
|
179
183
|
end
|
180
184
|
|
181
|
-
def attribute(name, template: false, rel: nil, &block)
|
185
|
+
def attribute(name, template: false, rel: nil, type: :value, &block)
|
182
186
|
self._attributes = self._attributes << {
|
183
|
-
:name => name, :template => template, :rel => rel, :
|
187
|
+
:name => name, :template => template, :rel => rel, :type => type,
|
188
|
+
:block => block
|
184
189
|
}
|
185
190
|
end
|
186
191
|
|
data/lib/conglomerate/version.rb
CHANGED
data/spec/conglomerate_spec.rb
CHANGED
@@ -15,7 +15,7 @@ class ConglomerateTestSerializer
|
|
15
15
|
attribute :roster_id, :rel => :roster do |item|
|
16
16
|
roster_url(item.roster_id)
|
17
17
|
end
|
18
|
-
attribute :team_ids, :rel => :teams do |item|
|
18
|
+
attribute :team_ids, :rel => :teams, :type => :array do |item|
|
19
19
|
team_url(item.team_ids.join(","))
|
20
20
|
end
|
21
21
|
attribute :user_ids, :rel => :users do |item|
|
@@ -156,7 +156,7 @@ describe Conglomerate do
|
|
156
156
|
{"name" => "id", "value" => 1},
|
157
157
|
{"name" => "event_id", "value" => 2},
|
158
158
|
{"name" => "roster_id", "value" => nil},
|
159
|
-
{"name" => "team_ids", "
|
159
|
+
{"name" => "team_ids", "array" => [1,2]},
|
160
160
|
{"name" => "user_ids", "value" => []}
|
161
161
|
],
|
162
162
|
"links" => [
|
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.3.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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|