alephant-broker 2.1.0 → 2.1.1

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: 70f99d4f4a6e8be1fa904432ebc5c88582b798e4
4
- data.tar.gz: 1d20ca33dea4ced011ed482e08f4f8ad026f874a
3
+ metadata.gz: c8260c3c562810f056f45d46d56a3d5456cf10ab
4
+ data.tar.gz: b2d1e13aaf854e7c1b9ed76c0a8505d49bbc191c
5
5
  SHA512:
6
- metadata.gz: 4ffed8d1b703c047dd93c24a805f5a0da2a68377a413d5470334da27e07b044d7e85f8dd67da06bac7bc6acbebc8fcd97a830870a4fc8454636e1863ec22fad7
7
- data.tar.gz: 2330d1a13a6c61515514bd04939ae9374f0819cd91bc74bf5c9493b7df44dc1207ad552deb8246c0783f49ea741dbc511cff26bc8f5342af754d95194445049a
6
+ metadata.gz: f73fff98e5832614f68af4473ec6d6b05faa2a346cc5de5e51c60784c09d4dbbf8cbf267b8152a6686ba82d3d948d19e4239ef6a8d555efc574c8300ad95c1bf
7
+ data.tar.gz: 484cefb4a13f492438d7eab51c5bf9bf5a7603a46695846c1bb8187a8ca0bb8ff80464a14b5ff55f1dddc61ad226faab974198080c221f489125c35224ab8378
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_runtime_dependency 'alephant-logger'
37
37
  spec.add_runtime_dependency 'alephant-sequencer'
38
38
  spec.add_runtime_dependency "dalli-elasticache"
39
- spec.add_runtime_dependency 'pmap'
39
+ spec.add_runtime_dependency "pmap"
40
40
  spec.add_runtime_dependency "faraday"
41
+ spec.add_runtime_dependency "crimp"
41
42
  end
@@ -12,8 +12,8 @@ module Alephant
12
12
  @load_strategy = load_strategy
13
13
  end
14
14
 
15
- def create(id, batch_id, raw_options)
16
- component_meta = ComponentMeta.new(id, batch_id, raw_options)
15
+ def create(id, batch_id, options)
16
+ component_meta = ComponentMeta.new(id, batch_id, options)
17
17
  Component.new(
18
18
  component_meta,
19
19
  @load_strategy.load(component_meta)
@@ -1,13 +1,13 @@
1
1
  module Alephant
2
2
  module Broker
3
3
  class ComponentMeta
4
- attr_reader :id, :raw_options, :batch_id
4
+ attr_reader :id, :options, :batch_id
5
5
  attr_accessor :cached
6
6
 
7
- def initialize(id, batch_id, raw_options)
7
+ def initialize(id, batch_id, options)
8
8
  @id = id
9
9
  @batch_id = batch_id
10
- @raw_options = raw_options
10
+ @options = options
11
11
  @cached = true
12
12
  end
13
13
 
@@ -15,13 +15,6 @@ module Alephant
15
15
  "#{id}/#{opts_hash}/#{version}"
16
16
  end
17
17
 
18
- def options
19
- @options ||= raw_options.split('&').reduce({}) do |object, key_pair|
20
- key, value = key_pair.split('=')
21
- object.tap { |o| o.store(key.to_sym, value) }
22
- end
23
- end
24
-
25
18
  def version
26
19
  Broker.config.fetch(
27
20
  'elasticache_cache_version', 'not available'
@@ -35,8 +35,16 @@ module Alephant
35
35
  parse(rack_input) if post?
36
36
  end
37
37
 
38
+ def options
39
+ convert_keys Rack::Utils.parse_nested_query(query)
40
+ end
41
+
38
42
  private
39
43
 
44
+ def convert_keys(hash)
45
+ Hash[ hash.map { |k, v| [k.to_sym, v] } ]
46
+ end
47
+
40
48
  def rack_input
41
49
  (settings['rack.input'].read).tap { settings['rack.input'].rewind }
42
50
  end
@@ -56,7 +56,7 @@ module Alephant
56
56
  def url_for(component_meta)
57
57
  url_generator.generate(
58
58
  component_meta.id,
59
- component_meta.raw_options
59
+ component_meta.options
60
60
  )
61
61
  end
62
62
  end
@@ -1,5 +1,4 @@
1
1
  require 'alephant/logger'
2
- require 'alephant/broker/component'
3
2
  require 'alephant/broker/errors/invalid_asset_id'
4
3
 
5
4
  module Alephant
@@ -12,13 +11,17 @@ module Alephant
12
11
 
13
12
  def initialize(component_factory, env = nil)
14
13
  return if env.nil?
14
+ @component = component_factory.create(
15
+ component_id(env.path),
16
+ nil,
17
+ env.options
18
+ )
19
+ end
15
20
 
16
- component_id = env.path.split('/')[2] || nil
17
- raw_options = env.query
18
-
19
- raise InvalidAssetId.new("No Asset ID specified") if component_id.nil?
21
+ private
20
22
 
21
- @component = component_factory.create(component_id, nil, raw_options)
23
+ def component_id(path)
24
+ path.split('/')[2] || (raise InvalidAssetId.new 'No Asset ID specified')
22
25
  end
23
26
  end
24
27
  end
@@ -22,16 +22,12 @@ module Alephant
22
22
 
23
23
  private
24
24
 
25
- def build_query(hash)
26
- hash.nil? ? '' : Rack::Utils.build_query(hash)
27
- end
28
-
29
25
  def components_for(env)
30
26
  env.data['components'].pmap do |c|
31
27
  @component_factory.create(
32
28
  c['component'],
33
29
  batch_id,
34
- build_query(c['options'])
30
+ c['options']
35
31
  )
36
32
  end
37
33
  end
@@ -26,7 +26,7 @@ module Alephant
26
26
 
27
27
  def json
28
28
  logger.info "Broker: Batch load started (#{batch_id})"
29
- result = components.map do |component|
29
+ components.map do |component|
30
30
  {
31
31
  'component' => component.id,
32
32
  'options' => component.options,
@@ -34,10 +34,7 @@ module Alephant
34
34
  'content_type' => component.content_type,
35
35
  'body' => component.content
36
36
  }
37
- end
38
- logger.info "Broker: Batch load done (#{batch_id})"
39
-
40
- result
37
+ end.tap { logger.info "Broker: Batch load done (#{batch_id})" }
41
38
  end
42
39
 
43
40
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Broker
3
- VERSION = "2.1.0"
3
+ VERSION = "2.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,20 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Alephant::Broker::Environment do
4
+ subject { described_class.new env }
5
+ let(:env) do
6
+ {
7
+ 'QUERY_STRING' => 'variant=K03000001'
8
+ }
9
+ end
10
+
11
+ describe '#options' do
12
+ let(:expected) do
13
+ {
14
+ :variant => "K03000001"
15
+ }
16
+ end
17
+
18
+ specify { expect(subject.options).to eq expected }
19
+ end
20
+ end
data/spec/http_spec.rb CHANGED
@@ -4,7 +4,12 @@ describe Alephant::Broker::LoadStrategy::HTTP do
4
4
  subject { described_class.new(url_generator) }
5
5
 
6
6
  let(:component_meta) do
7
- double('Alephant::Broker::ComponentMeta', cache_key: 'cache_key', id: 'test')
7
+ double(
8
+ 'Alephant::Broker::ComponentMeta',
9
+ cache_key: 'cache_key',
10
+ id: 'test',
11
+ options: {}
12
+ )
8
13
  end
9
14
  let(:url_generator) { double(generate: "http://foo.bar") }
10
15
  let(:cache) { double('Alephant::Broker::Cache::Client') }
@@ -35,7 +40,6 @@ describe Alephant::Broker::LoadStrategy::HTTP do
35
40
  before :each do
36
41
  allow(cache).to receive(:get).and_yield
37
42
  allow(component_meta).to receive(:'cached=').with(false) { false }
38
- allow(component_meta).to receive(:raw_options).and_return Hash.new
39
43
  end
40
44
 
41
45
  context "and available over HTTP" do
metadata CHANGED
@@ -1,267 +1,281 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
15
20
  requirement: !ruby/object:Gem::Requirement
16
21
  requirements:
17
22
  - - '>='
18
23
  - !ruby/object:Gem::Version
19
24
  version: '0'
20
- type: :development
21
25
  prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-nc
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
31
  - - '>='
25
32
  - !ruby/object:Gem::Version
26
33
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec-nc
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
36
  - - '>='
32
37
  - !ruby/object:Gem::Version
33
38
  version: '0'
34
- type: :development
35
39
  prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
45
  - - '>='
39
46
  - !ruby/object:Gem::Version
40
47
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: guard
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
50
  - - '>='
46
51
  - !ruby/object:Gem::Version
47
52
  version: '0'
48
- type: :development
49
53
  prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: guard-rspec
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
64
  - - '>='
60
65
  - !ruby/object:Gem::Version
61
66
  version: '0'
62
- type: :development
63
67
  prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
64
71
  version_requirements: !ruby/object:Gem::Requirement
65
72
  requirements:
66
73
  - - '>='
67
74
  - !ruby/object:Gem::Version
68
75
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
76
  requirement: !ruby/object:Gem::Requirement
72
77
  requirements:
73
78
  - - '>='
74
79
  - !ruby/object:Gem::Version
75
80
  version: '0'
76
- type: :development
77
81
  prerelease: false
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-remote
78
85
  version_requirements: !ruby/object:Gem::Requirement
79
86
  requirements:
80
87
  - - '>='
81
88
  - !ruby/object:Gem::Version
82
89
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry-remote
85
90
  requirement: !ruby/object:Gem::Requirement
86
91
  requirements:
87
92
  - - '>='
88
93
  - !ruby/object:Gem::Version
89
94
  version: '0'
90
- type: :development
91
95
  prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
92
99
  version_requirements: !ruby/object:Gem::Requirement
93
100
  requirements:
94
101
  - - '>='
95
102
  - !ruby/object:Gem::Version
96
103
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: pry-nav
99
104
  requirement: !ruby/object:Gem::Requirement
100
105
  requirements:
101
106
  - - '>='
102
107
  - !ruby/object:Gem::Version
103
108
  version: '0'
104
- type: :development
105
109
  prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
110
+ type: :development
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake-rspec
113
- requirement: !ruby/object:Gem::Requirement
113
+ version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: 0.0.2
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
118
+ requirement: !ruby/object:Gem::Requirement
121
119
  requirements:
122
120
  - - '>='
123
121
  - !ruby/object:Gem::Version
124
122
  version: 0.0.2
123
+ prerelease: false
124
+ type: :development
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: bundler
127
- requirement: !ruby/object:Gem::Requirement
127
+ version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: '1.5'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
132
+ requirement: !ruby/object:Gem::Requirement
135
133
  requirements:
136
134
  - - ~>
137
135
  - !ruby/object:Gem::Version
138
136
  version: '1.5'
137
+ prerelease: false
138
+ type: :development
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rake
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
141
146
  requirement: !ruby/object:Gem::Requirement
142
147
  requirements:
143
148
  - - '>='
144
149
  - !ruby/object:Gem::Version
145
150
  version: '0'
146
- type: :development
147
151
  prerelease: false
152
+ type: :development
153
+ - !ruby/object:Gem::Dependency
154
+ name: rack-test
148
155
  version_requirements: !ruby/object:Gem::Requirement
149
156
  requirements:
150
157
  - - '>='
151
158
  - !ruby/object:Gem::Version
152
159
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: rack-test
155
160
  requirement: !ruby/object:Gem::Requirement
156
161
  requirements:
157
162
  - - '>='
158
163
  - !ruby/object:Gem::Version
159
164
  version: '0'
160
- type: :development
161
165
  prerelease: false
166
+ type: :development
167
+ - !ruby/object:Gem::Dependency
168
+ name: alephant-lookup
162
169
  version_requirements: !ruby/object:Gem::Requirement
163
170
  requirements:
164
171
  - - '>='
165
172
  - !ruby/object:Gem::Version
166
173
  version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: alephant-lookup
169
174
  requirement: !ruby/object:Gem::Requirement
170
175
  requirements:
171
176
  - - '>='
172
177
  - !ruby/object:Gem::Version
173
178
  version: '0'
174
- type: :runtime
175
179
  prerelease: false
180
+ type: :runtime
181
+ - !ruby/object:Gem::Dependency
182
+ name: alephant-cache
176
183
  version_requirements: !ruby/object:Gem::Requirement
177
184
  requirements:
178
185
  - - '>='
179
186
  - !ruby/object:Gem::Version
180
187
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: alephant-cache
183
188
  requirement: !ruby/object:Gem::Requirement
184
189
  requirements:
185
190
  - - '>='
186
191
  - !ruby/object:Gem::Version
187
192
  version: '0'
188
- type: :runtime
189
193
  prerelease: false
194
+ type: :runtime
195
+ - !ruby/object:Gem::Dependency
196
+ name: alephant-logger
190
197
  version_requirements: !ruby/object:Gem::Requirement
191
198
  requirements:
192
199
  - - '>='
193
200
  - !ruby/object:Gem::Version
194
201
  version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: alephant-logger
197
202
  requirement: !ruby/object:Gem::Requirement
198
203
  requirements:
199
204
  - - '>='
200
205
  - !ruby/object:Gem::Version
201
206
  version: '0'
202
- type: :runtime
203
207
  prerelease: false
208
+ type: :runtime
209
+ - !ruby/object:Gem::Dependency
210
+ name: alephant-sequencer
204
211
  version_requirements: !ruby/object:Gem::Requirement
205
212
  requirements:
206
213
  - - '>='
207
214
  - !ruby/object:Gem::Version
208
215
  version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: alephant-sequencer
211
216
  requirement: !ruby/object:Gem::Requirement
212
217
  requirements:
213
218
  - - '>='
214
219
  - !ruby/object:Gem::Version
215
220
  version: '0'
216
- type: :runtime
217
221
  prerelease: false
222
+ type: :runtime
223
+ - !ruby/object:Gem::Dependency
224
+ name: dalli-elasticache
218
225
  version_requirements: !ruby/object:Gem::Requirement
219
226
  requirements:
220
227
  - - '>='
221
228
  - !ruby/object:Gem::Version
222
229
  version: '0'
223
- - !ruby/object:Gem::Dependency
224
- name: dalli-elasticache
225
230
  requirement: !ruby/object:Gem::Requirement
226
231
  requirements:
227
232
  - - '>='
228
233
  - !ruby/object:Gem::Version
229
234
  version: '0'
230
- type: :runtime
231
235
  prerelease: false
236
+ type: :runtime
237
+ - !ruby/object:Gem::Dependency
238
+ name: pmap
232
239
  version_requirements: !ruby/object:Gem::Requirement
233
240
  requirements:
234
241
  - - '>='
235
242
  - !ruby/object:Gem::Version
236
243
  version: '0'
237
- - !ruby/object:Gem::Dependency
238
- name: pmap
239
244
  requirement: !ruby/object:Gem::Requirement
240
245
  requirements:
241
246
  - - '>='
242
247
  - !ruby/object:Gem::Version
243
248
  version: '0'
244
- type: :runtime
245
249
  prerelease: false
250
+ type: :runtime
251
+ - !ruby/object:Gem::Dependency
252
+ name: faraday
246
253
  version_requirements: !ruby/object:Gem::Requirement
247
254
  requirements:
248
255
  - - '>='
249
256
  - !ruby/object:Gem::Version
250
257
  version: '0'
251
- - !ruby/object:Gem::Dependency
252
- name: faraday
253
258
  requirement: !ruby/object:Gem::Requirement
254
259
  requirements:
255
260
  - - '>='
256
261
  - !ruby/object:Gem::Version
257
262
  version: '0'
258
- type: :runtime
259
263
  prerelease: false
264
+ type: :runtime
265
+ - !ruby/object:Gem::Dependency
266
+ name: crimp
260
267
  version_requirements: !ruby/object:Gem::Requirement
261
268
  requirements:
262
269
  - - '>='
263
270
  - !ruby/object:Gem::Version
264
271
  version: '0'
272
+ requirement: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - '>='
275
+ - !ruby/object:Gem::Version
276
+ version: '0'
277
+ prerelease: false
278
+ type: :runtime
265
279
  description: Brokers requests for alephant components
266
280
  email:
267
281
  - stevenmajack@gmail.com
@@ -303,6 +317,7 @@ files:
303
317
  - lib/alephant/broker/response/factory.rb
304
318
  - lib/alephant/broker/response/multi.rb
305
319
  - lib/alephant/broker/version.rb
320
+ - spec/environment_spec.rb
306
321
  - spec/fixtures/json/batch.json
307
322
  - spec/fixtures/json/batch_compiled.json
308
323
  - spec/http_spec.rb
@@ -313,7 +328,7 @@ homepage: https://github.com/BBC-News/alephant-broker
313
328
  licenses:
314
329
  - MIT
315
330
  metadata: {}
316
- post_install_message:
331
+ post_install_message:
317
332
  rdoc_options: []
318
333
  require_paths:
319
334
  - lib
@@ -328,12 +343,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
343
  - !ruby/object:Gem::Version
329
344
  version: '0'
330
345
  requirements: []
331
- rubyforge_project:
332
- rubygems_version: 2.0.14
333
- signing_key:
346
+ rubyforge_project:
347
+ rubygems_version: 2.1.9
348
+ signing_key:
334
349
  specification_version: 4
335
350
  summary: Brokers requests for alephant components
336
351
  test_files:
352
+ - spec/environment_spec.rb
337
353
  - spec/fixtures/json/batch.json
338
354
  - spec/fixtures/json/batch_compiled.json
339
355
  - spec/http_spec.rb