carbon 2.2.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +15 -0
- data/Gemfile +0 -10
- data/Rakefile +10 -11
- data/carbon.gemspec +18 -6
- data/lib/carbon.rb +9 -61
- data/lib/carbon/query.rb +140 -0
- data/lib/carbon/query_pool.rb +11 -0
- data/lib/carbon/shell/emitter.rb +1 -1
- data/lib/carbon/version.rb +1 -1
- data/spec/carbon/query_spec.rb +106 -0
- data/spec/carbon_spec.rb +237 -0
- data/spec/cassettes/2006_Altima.yml +69 -0
- data/spec/cassettes/2006_Altima_in_2010.yml +230 -0
- data/spec/cassettes/2006_Altima_in_2011.yml +1239 -0
- data/spec/cassettes/Flight.yml +59 -0
- data/spec/cassettes/Flight_and_Automobile.yml +60 -0
- data/spec/cassettes/LAX-_SFO_flight.yml +74 -0
- data/spec/cassettes/Monkey.yml +42 -0
- data/spec/cassettes/carbon_bp_com_flight.yml +58 -0
- data/spec/cassettes/flight_with_key_1.yml +59 -0
- data/spec/cassettes/flight_with_key_2.yml +59 -0
- data/spec/cassettes/timeframed_flight.yml +59 -0
- data/spec/helper.rb +25 -0
- data/spec/support/my_nissan_altima.rb +36 -0
- metadata +200 -13
- data/lib/carbon/future.rb +0 -109
- data/test/carbon_test.rb +0 -302
- data/test/helper.rb +0 -25
data/spec/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
if ::Bundler.definition.specs['debugger'].first
|
4
|
+
require 'debugger'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'carbon'
|
8
|
+
|
9
|
+
$:.unshift File.expand_path('../support', __FILE__)
|
10
|
+
|
11
|
+
module Utilities
|
12
|
+
def flush_cache!
|
13
|
+
CacheMethod.config.storage.flush
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'vcr'
|
18
|
+
VCR.configure do |c|
|
19
|
+
c.cassette_library_dir = 'spec/cassettes'
|
20
|
+
c.hook_into :fakeweb
|
21
|
+
end
|
22
|
+
|
23
|
+
RSpec.configure do |c|
|
24
|
+
c.include Utilities
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class MyNissan
|
2
|
+
def name
|
3
|
+
'Nissan'
|
4
|
+
end
|
5
|
+
def to_s
|
6
|
+
raise "Not fair!"
|
7
|
+
end
|
8
|
+
alias :inspect :to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
class MyNissanAltima
|
12
|
+
class << self
|
13
|
+
def all(options)
|
14
|
+
raise unless options == { :order => :year }
|
15
|
+
[ new(2000), new(2001), new(2002), new(2003), new(2004) ]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def initialize(model_year)
|
19
|
+
@model_year = model_year
|
20
|
+
end
|
21
|
+
def make; MyNissan.new end
|
22
|
+
def model; 'Altima' end
|
23
|
+
def model_year; @model_year end # what BP knows as "year"
|
24
|
+
def fuel_type; 'R' end # what BP knows as "automobile_fuel" and keys on "code"
|
25
|
+
def nil_make; nil end
|
26
|
+
def nil_model; nil end
|
27
|
+
include Carbon
|
28
|
+
emit_as 'Automobile' do
|
29
|
+
provide(:make) { |my_nissan_altima| my_nissan_altima.make.try(:name) }
|
30
|
+
provide :model
|
31
|
+
provide :model_year, :as => :year
|
32
|
+
provide :fuel_type, :as => :automobile_fuel, :key => :code
|
33
|
+
provide(:nil_make) { |my_nissan_altima| my_nissan_altima.nil_make.try(:blam!) }
|
34
|
+
provide :nil_model
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: bombshell
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: brighter_planet_metadata
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -76,7 +76,23 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: celluloid
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.11.0
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.11.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: conversions
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
81
97
|
none: false
|
82
98
|
requirements:
|
@@ -92,7 +108,7 @@ dependencies:
|
|
92
108
|
- !ruby/object:Gem::Version
|
93
109
|
version: '0'
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
111
|
+
name: hashie
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
97
113
|
none: false
|
98
114
|
requirements:
|
@@ -108,7 +124,7 @@ dependencies:
|
|
108
124
|
- !ruby/object:Gem::Version
|
109
125
|
version: '0'
|
110
126
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
127
|
+
name: multi_json
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|
113
129
|
none: false
|
114
130
|
requirements:
|
@@ -123,6 +139,150 @@ dependencies:
|
|
123
139
|
- - ! '>='
|
124
140
|
- !ruby/object:Gem::Version
|
125
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: aruba
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: avro
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: cucumber
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: fakeweb
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
type: :development
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
- !ruby/object:Gem::Dependency
|
207
|
+
name: rake
|
208
|
+
requirement: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
210
|
+
requirements:
|
211
|
+
- - ! '>='
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '0'
|
214
|
+
type: :development
|
215
|
+
prerelease: false
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
218
|
+
requirements:
|
219
|
+
- - ! '>='
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
- !ruby/object:Gem::Dependency
|
223
|
+
name: rspec
|
224
|
+
requirement: !ruby/object:Gem::Requirement
|
225
|
+
none: false
|
226
|
+
requirements:
|
227
|
+
- - ! '>='
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
none: false
|
234
|
+
requirements:
|
235
|
+
- - ! '>='
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
238
|
+
- !ruby/object:Gem::Dependency
|
239
|
+
name: timeframe
|
240
|
+
requirement: !ruby/object:Gem::Requirement
|
241
|
+
none: false
|
242
|
+
requirements:
|
243
|
+
- - ! '>='
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
version: '0'
|
246
|
+
type: :development
|
247
|
+
prerelease: false
|
248
|
+
version_requirements: !ruby/object:Gem::Requirement
|
249
|
+
none: false
|
250
|
+
requirements:
|
251
|
+
- - ! '>='
|
252
|
+
- !ruby/object:Gem::Version
|
253
|
+
version: '0'
|
254
|
+
- !ruby/object:Gem::Dependency
|
255
|
+
name: vcr
|
256
|
+
requirement: !ruby/object:Gem::Requirement
|
257
|
+
none: false
|
258
|
+
requirements:
|
259
|
+
- - ! '>='
|
260
|
+
- !ruby/object:Gem::Version
|
261
|
+
version: '0'
|
262
|
+
type: :development
|
263
|
+
prerelease: false
|
264
|
+
version_requirements: !ruby/object:Gem::Requirement
|
265
|
+
none: false
|
266
|
+
requirements:
|
267
|
+
- - ! '>='
|
268
|
+
- !ruby/object:Gem::Version
|
269
|
+
version: '0'
|
270
|
+
- !ruby/object:Gem::Dependency
|
271
|
+
name: yard
|
272
|
+
requirement: !ruby/object:Gem::Requirement
|
273
|
+
none: false
|
274
|
+
requirements:
|
275
|
+
- - ! '>='
|
276
|
+
- !ruby/object:Gem::Version
|
277
|
+
version: '0'
|
278
|
+
type: :development
|
279
|
+
prerelease: false
|
280
|
+
version_requirements: !ruby/object:Gem::Requirement
|
281
|
+
none: false
|
282
|
+
requirements:
|
283
|
+
- - ! '>='
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '0'
|
126
286
|
description: Brighter Planet API client for Ruby
|
127
287
|
email:
|
128
288
|
- seamus@abshere.net
|
@@ -147,13 +307,27 @@ files:
|
|
147
307
|
- features/shell.feature
|
148
308
|
- features/support/env.rb
|
149
309
|
- lib/carbon.rb
|
150
|
-
- lib/carbon/
|
310
|
+
- lib/carbon/query.rb
|
311
|
+
- lib/carbon/query_pool.rb
|
151
312
|
- lib/carbon/registry.rb
|
152
313
|
- lib/carbon/shell.rb
|
153
314
|
- lib/carbon/shell/emitter.rb
|
154
315
|
- lib/carbon/version.rb
|
155
|
-
-
|
156
|
-
-
|
316
|
+
- spec/carbon/query_spec.rb
|
317
|
+
- spec/carbon_spec.rb
|
318
|
+
- spec/cassettes/2006_Altima.yml
|
319
|
+
- spec/cassettes/2006_Altima_in_2010.yml
|
320
|
+
- spec/cassettes/2006_Altima_in_2011.yml
|
321
|
+
- spec/cassettes/Flight.yml
|
322
|
+
- spec/cassettes/Flight_and_Automobile.yml
|
323
|
+
- spec/cassettes/LAX-_SFO_flight.yml
|
324
|
+
- spec/cassettes/Monkey.yml
|
325
|
+
- spec/cassettes/carbon_bp_com_flight.yml
|
326
|
+
- spec/cassettes/flight_with_key_1.yml
|
327
|
+
- spec/cassettes/flight_with_key_2.yml
|
328
|
+
- spec/cassettes/timeframed_flight.yml
|
329
|
+
- spec/helper.rb
|
330
|
+
- spec/support/my_nissan_altima.rb
|
157
331
|
homepage: https://github.com/brighterplanet/carbon
|
158
332
|
licenses: []
|
159
333
|
post_install_message:
|
@@ -174,13 +348,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
348
|
version: '0'
|
175
349
|
requirements: []
|
176
350
|
rubyforge_project:
|
177
|
-
rubygems_version: 1.8.
|
351
|
+
rubygems_version: 1.8.24
|
178
352
|
signing_key:
|
179
353
|
specification_version: 3
|
180
354
|
summary: Brighter Planet API client for Ruby
|
181
355
|
test_files:
|
182
356
|
- features/shell.feature
|
183
357
|
- features/support/env.rb
|
184
|
-
-
|
185
|
-
-
|
358
|
+
- spec/carbon/query_spec.rb
|
359
|
+
- spec/carbon_spec.rb
|
360
|
+
- spec/cassettes/2006_Altima.yml
|
361
|
+
- spec/cassettes/2006_Altima_in_2010.yml
|
362
|
+
- spec/cassettes/2006_Altima_in_2011.yml
|
363
|
+
- spec/cassettes/Flight.yml
|
364
|
+
- spec/cassettes/Flight_and_Automobile.yml
|
365
|
+
- spec/cassettes/LAX-_SFO_flight.yml
|
366
|
+
- spec/cassettes/Monkey.yml
|
367
|
+
- spec/cassettes/carbon_bp_com_flight.yml
|
368
|
+
- spec/cassettes/flight_with_key_1.yml
|
369
|
+
- spec/cassettes/flight_with_key_2.yml
|
370
|
+
- spec/cassettes/timeframed_flight.yml
|
371
|
+
- spec/helper.rb
|
372
|
+
- spec/support/my_nissan_altima.rb
|
186
373
|
has_rdoc:
|
data/lib/carbon/future.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'net/http'
|
3
|
-
require 'cache_method'
|
4
|
-
require 'hashie/mash'
|
5
|
-
require 'multi_json'
|
6
|
-
|
7
|
-
module Carbon
|
8
|
-
# @private
|
9
|
-
class Future
|
10
|
-
class << self
|
11
|
-
def wrap(plain_query_or_o)
|
12
|
-
future = if plain_query_or_o.is_a?(::Array)
|
13
|
-
new(*plain_query_or_o)
|
14
|
-
else
|
15
|
-
new(*plain_query_or_o.as_impact_query)
|
16
|
-
end
|
17
|
-
future.object = plain_query_or_o
|
18
|
-
future
|
19
|
-
end
|
20
|
-
|
21
|
-
def single(future)
|
22
|
-
uri = ::URI.parse("#{future.domain}/#{future.emitter.underscore.pluralize}.json")
|
23
|
-
raw_result = ::Net::HTTP.post_form(uri, future.params)
|
24
|
-
future.finalize raw_result.code.to_i, raw_result.body
|
25
|
-
future
|
26
|
-
end
|
27
|
-
|
28
|
-
def multi(futures)
|
29
|
-
uniq_pending_futures = futures.uniq.select { |future| future.pending? }
|
30
|
-
while (set = uniq_pending_futures.pop(Carbon::CONCURRENCY)).any?
|
31
|
-
ts = set.map do |future|
|
32
|
-
::Thread.new { single future }
|
33
|
-
end
|
34
|
-
ts.each do |t|
|
35
|
-
t.join
|
36
|
-
end
|
37
|
-
end
|
38
|
-
futures
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
attr_reader :emitter
|
43
|
-
attr_reader :params
|
44
|
-
attr_reader :domain
|
45
|
-
|
46
|
-
attr_accessor :object
|
47
|
-
|
48
|
-
def initialize(emitter, params = {})
|
49
|
-
@result = nil
|
50
|
-
@emitter = emitter
|
51
|
-
params = params.dup || {}
|
52
|
-
@domain = params.delete(:domain) || Carbon.domain
|
53
|
-
if Carbon.key and not params.has_key?(:key)
|
54
|
-
params[:key] = Carbon.key
|
55
|
-
end
|
56
|
-
@params = params
|
57
|
-
end
|
58
|
-
|
59
|
-
def multi!
|
60
|
-
@multi = true
|
61
|
-
end
|
62
|
-
|
63
|
-
def multi?
|
64
|
-
@multi == true
|
65
|
-
end
|
66
|
-
|
67
|
-
def pending?
|
68
|
-
@result.nil? and !cache_method_cached?(:result)
|
69
|
-
end
|
70
|
-
|
71
|
-
def finalize(code, body = nil)
|
72
|
-
memo = ::Hashie::Mash.new
|
73
|
-
memo.code = code
|
74
|
-
case code
|
75
|
-
when (200..299)
|
76
|
-
memo.success = true
|
77
|
-
memo.merge! ::MultiJson.decode(body)
|
78
|
-
else
|
79
|
-
memo.success = false
|
80
|
-
memo.errors = [body]
|
81
|
-
end
|
82
|
-
@result = memo
|
83
|
-
self.result # make sure it gets cached
|
84
|
-
end
|
85
|
-
|
86
|
-
def result
|
87
|
-
if @result
|
88
|
-
@result
|
89
|
-
elsif not multi?
|
90
|
-
Future.single self
|
91
|
-
@result
|
92
|
-
end
|
93
|
-
end
|
94
|
-
cache_method :result, 3_600 # one hour
|
95
|
-
|
96
|
-
def as_cache_key
|
97
|
-
[ @domain, @emitter, @params ]
|
98
|
-
end
|
99
|
-
|
100
|
-
def hash
|
101
|
-
as_cache_key.hash
|
102
|
-
end
|
103
|
-
|
104
|
-
def eql?(other)
|
105
|
-
as_cache_key == other.as_cache_key
|
106
|
-
end
|
107
|
-
alias :== :eql?
|
108
|
-
end
|
109
|
-
end
|