emitter 0.0.13 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/emitter.rb CHANGED
@@ -1,11 +1,3 @@
1
- require 'cohort_scope'
2
- require 'falls_back_on'
3
- require 'falls_back_on/active_record_ext'
4
- # sabshere 8/15/10 why aren't these required here?
5
- # require 'characterizable'
6
- # require 'leap'
7
- # require 'weighted_average'
8
-
9
1
  module BrighterPlanet
10
2
  module Emitter
11
3
  def included(base)
@@ -13,14 +5,33 @@ module BrighterPlanet
13
5
 
14
6
  emitter_klass = self.to_s.split('::').last.underscore
15
7
 
16
- require "#{emitter_klass}/carbon_model"
17
- require "#{emitter_klass}/characterization"
18
- require "#{emitter_klass}/data"
19
- require "#{emitter_klass}/summarization"
8
+ %w{carbon_model characterization data fallback relationships summarization}.each do |component|
9
+ begin
10
+ require "#{emitter_klass}/#{component}"
11
+ rescue LoadError
12
+ end
13
+ end
20
14
 
15
+ require 'leap'
16
+ require 'cohort_scope'
21
17
  base.send :include, const_get('CarbonModel')
18
+
19
+ require 'characterizable'
22
20
  base.send :include, const_get('Characterization')
21
+
22
+ require 'data_miner'
23
23
  base.send :include, const_get('Data')
24
+
25
+ if const_defined?('Fallback')
26
+ require 'falls_back_on'
27
+ require 'falls_back_on/active_record_ext'
28
+ base.send :include, const_get('Fallback')
29
+ end
30
+
31
+ if const_defined?('Relationships')
32
+ base.send :include, const_get('Relationships')
33
+ end
34
+
24
35
  base.send :include, const_get('Summarization')
25
36
  end
26
37
 
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrighterPlanet::Emitter do
4
+ describe '.included' do
5
+ before :all do
6
+ require 'active_record'
7
+ class Aircraft < ActiveRecord::Base; end
8
+ class Airship < ActiveRecord::Base; end
9
+
10
+ $:.unshift File.expand_path('fixtures/dirigible/lib', File.dirname(__FILE__))
11
+ require 'dirigible'
12
+ Airship.send :include, BrighterPlanet::Dirigible
13
+ Airship.execute_schema
14
+
15
+ $:.unshift File.expand_path('fixtures/biplane/lib', File.dirname(__FILE__))
16
+ end
17
+
18
+ it 'should include fallback if available' do
19
+ Airship.new.kind_of?(BrighterPlanet::Dirigible::Fallback).
20
+ should be_true
21
+ end
22
+
23
+ it 'should include relationships if available' do
24
+ Airship.new.kind_of?(BrighterPlanet::Dirigible::Relationships).
25
+ should be_true
26
+ end
27
+
28
+ it 'should not include fallback or relationships if there are none' do
29
+ expect do
30
+ require 'biplane'
31
+ Aircraft.send :include, BrighterPlanet::Biplane
32
+ end.should_not raise_error
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,18 @@
1
+ require 'leap'
2
+
3
+ module BrighterPlanet
4
+ module Biplane
5
+ module CarbonModel
6
+ def self.included(base)
7
+ base.extend ::Leap::Subject
8
+ base.decide :emission, :with => :characteristics do
9
+ committee :emission do # returns kg CO2e
10
+ quorum 'default' do
11
+ 100.0
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'characterizable'
2
+
3
+ module BrighterPlanet
4
+ module Biplane
5
+ module Characterization
6
+ def self.included(base)
7
+ base.send :include, Characterizable
8
+ base.characterize do
9
+ has :distance
10
+ has :payload
11
+ has :dirigible_class
12
+ end
13
+ base.add_implicit_characteristics
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require 'data_miner'
2
+
3
+ module BrighterPlanet
4
+ module Biplane
5
+ module Data
6
+ def self.included(base)
7
+ base.data_miner do
8
+ schema do
9
+ float :distance
10
+ float :payload
11
+ integer :dirigible_class_id
12
+ end
13
+
14
+ process :run_data_miner_on_belongs_to_associations
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'summary_judgement'
2
+
3
+ module BrighterPlanet
4
+ module Biplane
5
+ module Summarization
6
+ def self.included(base)
7
+ base.extend SummaryJudgement
8
+ base.summarize do |has|
9
+ has.identity 'dirigible'
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'emitter'
2
+
3
+ module BrighterPlanet
4
+ module Biplane
5
+ extend BrighterPlanet::Emitter
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'leap'
2
+
3
+ module BrighterPlanet
4
+ module Dirigible
5
+ module CarbonModel
6
+ def self.included(base)
7
+ base.extend ::Leap::Subject
8
+ base.decide :emission, :with => :characteristics do
9
+ committee :emission do # returns kg CO2e
10
+ quorum 'default' do
11
+ 100.0
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'characterizable'
2
+
3
+ module BrighterPlanet
4
+ module Dirigible
5
+ module Characterization
6
+ def self.included(base)
7
+ base.send :include, Characterizable
8
+ base.characterize do
9
+ has :distance
10
+ has :payload
11
+ has :dirigible_class
12
+ end
13
+ base.add_implicit_characteristics
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require 'data_miner'
2
+
3
+ module BrighterPlanet
4
+ module Dirigible
5
+ module Data
6
+ def self.included(base)
7
+ base.data_miner do
8
+ schema do
9
+ float :distance
10
+ float :payload
11
+ integer :dirigible_class_id
12
+ end
13
+
14
+ process :run_data_miner_on_belongs_to_associations
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module BrighterPlanet
2
+ module Dirigible
3
+ module Fallback
4
+ def self.included(base)
5
+ base.falls_back_on :distance => 100
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module BrighterPlanet
2
+ module Dirigible
3
+ module Relationships
4
+ def self.included(base)
5
+ base.belongs_to :dirigible_class
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'summary_judgement'
2
+
3
+ module BrighterPlanet
4
+ module Dirigible
5
+ module Summarization
6
+ def self.included(base)
7
+ base.extend SummaryJudgement
8
+ base.summarize do |has|
9
+ has.identity 'dirigible'
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'emitter'
2
+
3
+ module BrighterPlanet
4
+ module Dirigible
5
+ extend BrighterPlanet::Emitter
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'sniff'
6
+ Sniff.init File.join(File.dirname(__FILE__), '..', '..')
7
+
8
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
9
+ require 'emitter'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emitter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 13
10
- version: 0.0.13
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Rossmeissl
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-09-20 00:00:00 -04:00
22
+ date: 2010-09-21 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -119,9 +119,25 @@ dependencies:
119
119
  type: :development
120
120
  version_requirements: *id006
121
121
  - !ruby/object:Gem::Dependency
122
- name: activesupport
122
+ name: sniff
123
123
  prerelease: false
124
124
  requirement: &id007 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ~>
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ - 1
133
+ - 12
134
+ version: 0.1.12
135
+ type: :development
136
+ version_requirements: *id007
137
+ - !ruby/object:Gem::Dependency
138
+ name: activesupport
139
+ prerelease: false
140
+ requirement: &id008 !ruby/object:Gem::Requirement
125
141
  none: false
126
142
  requirements:
127
143
  - - ">="
@@ -133,11 +149,11 @@ dependencies:
133
149
  - 0
134
150
  version: 3.0.0
135
151
  type: :runtime
136
- version_requirements: *id007
152
+ version_requirements: *id008
137
153
  - !ruby/object:Gem::Dependency
138
154
  name: characterizable
139
155
  prerelease: false
140
- requirement: &id008 !ruby/object:Gem::Requirement
156
+ requirement: &id009 !ruby/object:Gem::Requirement
141
157
  none: false
142
158
  requirements:
143
159
  - - ">="
@@ -149,11 +165,11 @@ dependencies:
149
165
  - 16
150
166
  version: 0.0.16
151
167
  type: :runtime
152
- version_requirements: *id008
168
+ version_requirements: *id009
153
169
  - !ruby/object:Gem::Dependency
154
170
  name: cohort_scope
155
171
  prerelease: false
156
- requirement: &id009 !ruby/object:Gem::Requirement
172
+ requirement: &id010 !ruby/object:Gem::Requirement
157
173
  none: false
158
174
  requirements:
159
175
  - - ">="
@@ -165,11 +181,11 @@ dependencies:
165
181
  - 7
166
182
  version: 0.0.7
167
183
  type: :runtime
168
- version_requirements: *id009
184
+ version_requirements: *id010
169
185
  - !ruby/object:Gem::Dependency
170
186
  name: data_miner
171
187
  prerelease: false
172
- requirement: &id010 !ruby/object:Gem::Requirement
188
+ requirement: &id011 !ruby/object:Gem::Requirement
173
189
  none: false
174
190
  requirements:
175
191
  - - ">="
@@ -181,11 +197,11 @@ dependencies:
181
197
  - 3
182
198
  version: 0.5.3
183
199
  type: :runtime
184
- version_requirements: *id010
200
+ version_requirements: *id011
185
201
  - !ruby/object:Gem::Dependency
186
202
  name: earth
187
203
  prerelease: false
188
- requirement: &id011 !ruby/object:Gem::Requirement
204
+ requirement: &id012 !ruby/object:Gem::Requirement
189
205
  none: false
190
206
  requirements:
191
207
  - - ~>
@@ -197,11 +213,11 @@ dependencies:
197
213
  - 2
198
214
  version: 0.1.2
199
215
  type: :runtime
200
- version_requirements: *id011
216
+ version_requirements: *id012
201
217
  - !ruby/object:Gem::Dependency
202
218
  name: falls_back_on
203
219
  prerelease: false
204
- requirement: &id012 !ruby/object:Gem::Requirement
220
+ requirement: &id013 !ruby/object:Gem::Requirement
205
221
  none: false
206
222
  requirements:
207
223
  - - "="
@@ -213,11 +229,11 @@ dependencies:
213
229
  - 3
214
230
  version: 0.0.3
215
231
  type: :runtime
216
- version_requirements: *id012
232
+ version_requirements: *id013
217
233
  - !ruby/object:Gem::Dependency
218
234
  name: fast_timestamp
219
235
  prerelease: false
220
- requirement: &id013 !ruby/object:Gem::Requirement
236
+ requirement: &id014 !ruby/object:Gem::Requirement
221
237
  none: false
222
238
  requirements:
223
239
  - - ">="
@@ -229,11 +245,11 @@ dependencies:
229
245
  - 4
230
246
  version: 0.0.4
231
247
  type: :runtime
232
- version_requirements: *id013
248
+ version_requirements: *id014
233
249
  - !ruby/object:Gem::Dependency
234
250
  name: leap
235
251
  prerelease: false
236
- requirement: &id014 !ruby/object:Gem::Requirement
252
+ requirement: &id015 !ruby/object:Gem::Requirement
237
253
  none: false
238
254
  requirements:
239
255
  - - ">="
@@ -245,11 +261,11 @@ dependencies:
245
261
  - 3
246
262
  version: 0.4.3
247
263
  type: :runtime
248
- version_requirements: *id014
264
+ version_requirements: *id015
249
265
  - !ruby/object:Gem::Dependency
250
266
  name: summary_judgement
251
267
  prerelease: false
252
- requirement: &id015 !ruby/object:Gem::Requirement
268
+ requirement: &id016 !ruby/object:Gem::Requirement
253
269
  none: false
254
270
  requirements:
255
271
  - - ">="
@@ -261,11 +277,11 @@ dependencies:
261
277
  - 8
262
278
  version: 1.3.8
263
279
  type: :runtime
264
- version_requirements: *id015
280
+ version_requirements: *id016
265
281
  - !ruby/object:Gem::Dependency
266
282
  name: timeframe
267
283
  prerelease: false
268
- requirement: &id016 !ruby/object:Gem::Requirement
284
+ requirement: &id017 !ruby/object:Gem::Requirement
269
285
  none: false
270
286
  requirements:
271
287
  - - ">="
@@ -277,11 +293,11 @@ dependencies:
277
293
  - 8
278
294
  version: 0.0.8
279
295
  type: :runtime
280
- version_requirements: *id016
296
+ version_requirements: *id017
281
297
  - !ruby/object:Gem::Dependency
282
298
  name: weighted_average
283
299
  prerelease: false
284
- requirement: &id017 !ruby/object:Gem::Requirement
300
+ requirement: &id018 !ruby/object:Gem::Requirement
285
301
  none: false
286
302
  requirements:
287
303
  - - ">="
@@ -293,11 +309,11 @@ dependencies:
293
309
  - 4
294
310
  version: 0.0.4
295
311
  type: :runtime
296
- version_requirements: *id017
312
+ version_requirements: *id018
297
313
  - !ruby/object:Gem::Dependency
298
314
  name: rocco
299
315
  prerelease: false
300
- requirement: &id018 !ruby/object:Gem::Requirement
316
+ requirement: &id019 !ruby/object:Gem::Requirement
301
317
  none: false
302
318
  requirements:
303
319
  - - ~>
@@ -308,7 +324,7 @@ dependencies:
308
324
  - 4
309
325
  version: "0.4"
310
326
  type: :development
311
- version_requirements: *id018
327
+ version_requirements: *id019
312
328
  description: A software model in Ruby for the greenhouse gas emissions
313
329
  email: derek@brighterplanet.com
314
330
  executables: []
@@ -321,6 +337,20 @@ files:
321
337
  - README.rdoc
322
338
  - lib/emitter.rb
323
339
  - lib/emitter/tasks.rb
340
+ - spec/emitter_spec.rb
341
+ - spec/fixtures/biplane/lib/biplane/carbon_model.rb
342
+ - spec/fixtures/biplane/lib/biplane/characterization.rb
343
+ - spec/fixtures/biplane/lib/biplane/data.rb
344
+ - spec/fixtures/biplane/lib/biplane/summarization.rb
345
+ - spec/fixtures/biplane/lib/biplane.rb
346
+ - spec/fixtures/dirigible/lib/dirigible/carbon_model.rb
347
+ - spec/fixtures/dirigible/lib/dirigible/characterization.rb
348
+ - spec/fixtures/dirigible/lib/dirigible/data.rb
349
+ - spec/fixtures/dirigible/lib/dirigible/fallback.rb
350
+ - spec/fixtures/dirigible/lib/dirigible/relationships.rb
351
+ - spec/fixtures/dirigible/lib/dirigible/summarization.rb
352
+ - spec/fixtures/dirigible/lib/dirigible.rb
353
+ - spec/spec_helper.rb
324
354
  has_rdoc: true
325
355
  homepage: http://github.com/brighterplanet/emitter
326
356
  licenses: []
@@ -355,5 +385,18 @@ rubygems_version: 1.3.7
355
385
  signing_key:
356
386
  specification_version: 3
357
387
  summary: The mother of all carbon models
358
- test_files: []
359
-
388
+ test_files:
389
+ - spec/emitter_spec.rb
390
+ - spec/fixtures/biplane/lib/biplane/carbon_model.rb
391
+ - spec/fixtures/biplane/lib/biplane/characterization.rb
392
+ - spec/fixtures/biplane/lib/biplane/data.rb
393
+ - spec/fixtures/biplane/lib/biplane/summarization.rb
394
+ - spec/fixtures/biplane/lib/biplane.rb
395
+ - spec/fixtures/dirigible/lib/dirigible/carbon_model.rb
396
+ - spec/fixtures/dirigible/lib/dirigible/characterization.rb
397
+ - spec/fixtures/dirigible/lib/dirigible/data.rb
398
+ - spec/fixtures/dirigible/lib/dirigible/fallback.rb
399
+ - spec/fixtures/dirigible/lib/dirigible/relationships.rb
400
+ - spec/fixtures/dirigible/lib/dirigible/summarization.rb
401
+ - spec/fixtures/dirigible/lib/dirigible.rb
402
+ - spec/spec_helper.rb