tronprint 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module Tronprint
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/tronprint.rb CHANGED
@@ -50,7 +50,6 @@ module Tronprint
50
50
  # This is your Brighter Planet API key. Get one from
51
51
  # {keys.brighterplanet.com}[http://keys.brighterplanet.com]
52
52
  def brighter_planet_key
53
- @brighter_planet_key ||= ENV['TRONPRINT_API_KEY']
54
53
  @brighter_planet_key ||= config[:brighter_planet_key]
55
54
  end
56
55
 
@@ -90,6 +89,11 @@ module Tronprint
90
89
  load_config || default_config
91
90
  end
92
91
 
92
+ def config=(val)
93
+ @loaded_config = val
94
+ @default_config = val
95
+ end
96
+
93
97
  # Fetch the configuration stored in config/tronprint.yml.
94
98
  def load_config
95
99
  return @loaded_config unless @loaded_config.nil?
@@ -101,13 +105,22 @@ module Tronprint
101
105
  # are stored in `pwd`/tronprint_stats.yml. The application name
102
106
  # is assumed to be the name of the current directory.
103
107
  def default_config
104
- @default_config ||= {
105
- :aggregator_options => {
106
- :adapter => :YAML,
107
- :path => File.expand_path('tronprint_stats.yml', Dir.pwd)
108
- },
108
+ return @default_config unless @default_config.nil?
109
+ @default_config = {
109
110
  :application_name => File.basename(Dir.pwd)
110
111
  }
112
+ @default_config[:brighter_planet_key] = ENV['TRONPRINT_API_KEY'] if ENV['TRONPRINT_API_KEY']
113
+ if ENV['MONGOHQ_URL']
114
+ @default_config[:aggregator_options] = {
115
+ :url => ENV['MONGOHQ_URL'],
116
+ :adapter => :mongodb
117
+ }
118
+ end
119
+ @default_config[:aggregator_options] ||= {
120
+ :adapter => :YAML,
121
+ :path => File.expand_path('tronprint_stats.yml', Dir.pwd)
122
+ }
123
+ @default_config
111
124
  end
112
125
 
113
126
  # Calculate emissions using aggregated data. A call is made to
@@ -40,14 +40,8 @@ describe Tronprint do
40
40
  end
41
41
 
42
42
  describe '.brighter_planet_key' do
43
- it 'should return the key defined in ENV by default' do
44
- Tronprint.brighter_planet_key = nil
45
- ENV['TRONPRINT_API_KEY'] = 'abcc1234'
46
- Tronprint.brighter_planet_key.should == 'abcc1234'
47
- end
48
- it 'should return the key defined in the configuration by default if no ENV is given' do
49
- Tronprint.brighter_planet_key = nil
50
- ENV['TRONPRINT_API_KEY'] = nil
43
+ it 'should return the brighter_planet_key config option' do
44
+ Tronprint.instance_variable_set :@brighter_planet_key, nil
51
45
  Tronprint.stub!(:config).and_return({ :brighter_planet_key => 'aaa' })
52
46
  Tronprint.brighter_planet_key.should == 'aaa'
53
47
  end
@@ -82,9 +76,25 @@ describe Tronprint do
82
76
  end
83
77
 
84
78
  describe '.default_config' do
79
+ before :each do
80
+ Tronprint.instance_variable_set :@default_config, nil
81
+ end
82
+ after :each do
83
+ ENV['TRONPRINT_API_KEY'] = nil
84
+ ENV['MONGOHQ_URL'] = nil
85
+ end
85
86
  it 'should return a default configuration' do
86
87
  Tronprint.default_config.should be_an_instance_of(Hash)
87
88
  end
89
+ it 'should set the brighter_planet_key if ENV["TRONPRINT_API_KEY"] is set' do
90
+ ENV['TRONPRINT_API_KEY'] = 'abc123'
91
+ Tronprint.default_config[:brighter_planet_key].should == 'abc123'
92
+ end
93
+ it 'should use MongoHQ if ENV["MONGOHQ_URL"] is set' do
94
+ ENV['MONGOHQ_URL'] = 'mongodb://foo.com/bar'
95
+ Tronprint.default_config[:aggregator_options][:adapter].should == :mongodb
96
+ Tronprint.default_config[:aggregator_options][:url].should == 'mongodb://foo.com/bar'
97
+ end
88
98
  end
89
99
 
90
100
  describe '.total_duration' do
data/tronprint.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Tronprint::VERSION
8
8
 
9
9
  s.authors = ['Derek Kastner']
10
- s.date = "2011-01-26"
10
+ s.date = "2011-02-03"
11
11
  s.description = %q{A gem for monitoring the carbon footprint of your ruby app}
12
12
  s.email = %q{dkastner@gmail.com}
13
13
  s.homepage = %q{http://github.com/brighterplanet/tronprint}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 10
9
- version: 0.0.10
8
+ - 11
9
+ version: 0.0.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Derek Kastner
@@ -14,11 +14,12 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-26 00:00:00 -05:00
17
+ date: 2011-02-03 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cucumber
22
+ prerelease: false
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
@@ -28,10 +29,10 @@ dependencies:
28
29
  - 0
29
30
  version: "0"
30
31
  type: :development
31
- prerelease: false
32
32
  version_requirements: *id001
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bueller
35
+ prerelease: false
35
36
  requirement: &id002 !ruby/object:Gem::Requirement
36
37
  none: false
37
38
  requirements:
@@ -43,10 +44,10 @@ dependencies:
43
44
  - 2
44
45
  version: 0.0.2
45
46
  type: :development
46
- prerelease: false
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rake
50
+ prerelease: false
50
51
  requirement: &id003 !ruby/object:Gem::Requirement
51
52
  none: false
52
53
  requirements:
@@ -56,10 +57,10 @@ dependencies:
56
57
  - 0
57
58
  version: "0"
58
59
  type: :development
59
- prerelease: false
60
60
  version_requirements: *id003
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
+ prerelease: false
63
64
  requirement: &id004 !ruby/object:Gem::Requirement
64
65
  none: false
65
66
  requirements:
@@ -70,10 +71,10 @@ dependencies:
70
71
  - 0
71
72
  version: "2.0"
72
73
  type: :development
73
- prerelease: false
74
74
  version_requirements: *id004
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: sandbox
77
+ prerelease: false
77
78
  requirement: &id005 !ruby/object:Gem::Requirement
78
79
  none: false
79
80
  requirements:
@@ -83,10 +84,10 @@ dependencies:
83
84
  - 0
84
85
  version: "0"
85
86
  type: :development
86
- prerelease: false
87
87
  version_requirements: *id005
88
88
  - !ruby/object:Gem::Dependency
89
89
  name: carbon
90
+ prerelease: false
90
91
  requirement: &id006 !ruby/object:Gem::Requirement
91
92
  none: false
92
93
  requirements:
@@ -98,10 +99,10 @@ dependencies:
98
99
  - 3
99
100
  version: 1.0.3
100
101
  type: :runtime
101
- prerelease: false
102
102
  version_requirements: *id006
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: i18n
105
+ prerelease: false
105
106
  requirement: &id007 !ruby/object:Gem::Requirement
106
107
  none: false
107
108
  requirements:
@@ -111,10 +112,10 @@ dependencies:
111
112
  - 0
112
113
  version: "0"
113
114
  type: :runtime
114
- prerelease: false
115
115
  version_requirements: *id007
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: dkastner-moneta
118
+ prerelease: false
118
119
  requirement: &id008 !ruby/object:Gem::Requirement
119
120
  none: false
120
121
  requirements:
@@ -124,7 +125,6 @@ dependencies:
124
125
  - 0
125
126
  version: "0"
126
127
  type: :runtime
127
- prerelease: false
128
128
  version_requirements: *id008
129
129
  description: A gem for monitoring the carbon footprint of your ruby app
130
130
  email: dkastner@gmail.com
@@ -137,12 +137,12 @@ extra_rdoc_files:
137
137
  - README.rdoc
138
138
  files:
139
139
  - lib/tronprint/aggregator.rb
140
- - lib/tronprint/rails/generator.rb
141
- - lib/tronprint/rails/tronprint_helper.rb
142
- - lib/tronprint/version.rb
143
140
  - lib/tronprint/application.rb
144
141
  - lib/tronprint/cpu_monitor.rb
142
+ - lib/tronprint/rails/generator.rb
143
+ - lib/tronprint/rails/tronprint_helper.rb
145
144
  - lib/tronprint/rails.rb
145
+ - lib/tronprint/version.rb
146
146
  - lib/tronprint.rb
147
147
  - .document
148
148
  - .rspec
@@ -152,17 +152,17 @@ files:
152
152
  - autotest/discover.rb
153
153
  - LICENSE
154
154
  - README.rdoc
155
+ - spec/spec.opts
156
+ - spec/spec_helper.rb
157
+ - spec/tronprint/aggregator_spec.rb
155
158
  - spec/tronprint/application_spec.rb
156
- - spec/tronprint/rails/tronprint_helper_spec.rb
157
159
  - spec/tronprint/computer_spec.rb
158
- - spec/tronprint/aggregator_spec.rb
159
160
  - spec/tronprint/cpu_monitor_spec.rb
161
+ - spec/tronprint/rails/tronprint_helper_spec.rb
160
162
  - spec/tronprint_spec.rb
161
- - spec/spec.opts
162
- - spec/spec_helper.rb
163
+ - features/step_definitions/tronprint_steps.rb
163
164
  - features/support/env.rb
164
165
  - features/tronprint.feature
165
- - features/step_definitions/tronprint_steps.rb
166
166
  has_rdoc: true
167
167
  homepage: http://github.com/brighterplanet/tronprint
168
168
  licenses: []
@@ -177,7 +177,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- hash: 174585741
181
180
  segments:
182
181
  - 0
183
182
  version: "0"
@@ -186,7 +185,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
185
  requirements:
187
186
  - - ">="
188
187
  - !ruby/object:Gem::Version
189
- hash: 174585741
190
188
  segments:
191
189
  - 0
192
190
  version: "0"
@@ -198,14 +196,14 @@ signing_key:
198
196
  specification_version: 3
199
197
  summary: Ruby process carbon footprinter
200
198
  test_files:
199
+ - spec/spec.opts
200
+ - spec/spec_helper.rb
201
+ - spec/tronprint/aggregator_spec.rb
201
202
  - spec/tronprint/application_spec.rb
202
- - spec/tronprint/rails/tronprint_helper_spec.rb
203
203
  - spec/tronprint/computer_spec.rb
204
- - spec/tronprint/aggregator_spec.rb
205
204
  - spec/tronprint/cpu_monitor_spec.rb
205
+ - spec/tronprint/rails/tronprint_helper_spec.rb
206
206
  - spec/tronprint_spec.rb
207
- - spec/spec.opts
208
- - spec/spec_helper.rb
207
+ - features/step_definitions/tronprint_steps.rb
209
208
  - features/support/env.rb
210
209
  - features/tronprint.feature
211
- - features/step_definitions/tronprint_steps.rb