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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79cf2a21f974567cdf55b0a1e273292306c96140
4
- data.tar.gz: 882941211d941acbd16c88eefb0e51c0fad474bc
3
+ metadata.gz: 9da3788aca18b7373349738518eb060890f2bc0b
4
+ data.tar.gz: 13ce8616d35fa4e79621b924bc58d3444cbd0fcb
5
5
  SHA512:
6
- metadata.gz: 57d389ee559e86c32166f58fc6efbcc9a23d57a5c3dbadca1318ef0735ae366f46cea65ddc2f62bbf97014ee5bc363c21b6a107a6118e8e25d30a12676d4903f
7
- data.tar.gz: 568b17ac4a3c9bb36ec93aa8133926d6d42f39c0407351692eaa5b3a458682067fd7d5e514f337e74f350ec501a09c3db0fca35293ded8bf99a670ab2fe73226
6
+ metadata.gz: b82efadf83f9b16cb46617c81995e7e5b1df6e9706c08406aa0c33e0a2d45b9a10cb5fe2bfca3d62606409743da4ce329b1869ccf53f4cb0dd2e35f12673832c
7
+ data.tar.gz: 2647c169ae848cc2a0bfdd319b35e1dd2db0c30a2929ee1107f0a7e9bb9dec3b480fb35a9f8c63a740bb584859bf14ccd5fd25fc320659b7dacf3dbaaf0c1d53
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "coveralls", :require => false
4
+ gem "pry", :require => false
4
5
 
5
6
  gemspec
@@ -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 |name|
46
- {"name" => name.to_s, "value" => object.nil? ? "" : object.send(name)}
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
- names = self.class._attributes.map { |attr| attr[:name] }
79
- item = apply_data(item, :data => names, :object => object)
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 => [*data], :block => block
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, :block => block
187
+ :name => name, :template => template, :rel => rel, :type => type,
188
+ :block => block
184
189
  }
185
190
  end
186
191
 
@@ -1,3 +1,3 @@
1
1
  module Conglomerate
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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", "value" => [1,2]},
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.2.1
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-07 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler