sniff 0.0.15 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sniff.rb CHANGED
@@ -5,6 +5,17 @@ module Sniff
5
5
  File.join(File.dirname(__FILE__), '..')
6
6
  end
7
7
 
8
+ # Prepares the environment for running tests against Earth data and emitter
9
+ # gems.
10
+ #
11
+ # local_root: Root directory of the emitter gem to be tested (path to the repo)
12
+ #
13
+ # options:
14
+ # * :earth is the list of domains Earth.init should load (default: none)
15
+ # * :load_data determines whether fixture data is loaded (default: true)
16
+ # * :sqllogdev is a Logger log device used by ActiveRecord (default: nil)
17
+ # * :fixtures_path is the path to your gem's fixtures (default: local_root/lib/db/fixtures)
18
+ # * :logdev is a Logger log device used for general logging (default: nil)
8
19
  def init(local_root, options = {})
9
20
  options[:earth] ||= :none
10
21
 
@@ -6,6 +6,15 @@ require 'sqlite3'
6
6
  module Sniff
7
7
  class Database
8
8
  class << self
9
+ # Initialize a database used for testing emitter gems
10
+ #
11
+ # local_root: Root directory of the emitter gem to be tested (path to the repo)
12
+ # options:
13
+ # * :earth is the list of domains Earth.init should load (default: none)
14
+ # * :load_data determines whether fixture data is loaded (default: true)
15
+ # * :sqllogdev is a Logger log device used by ActiveRecord (default: nil)
16
+ # * :fixtures_path is the path to your gem's fixtures (default: local_root/lib/db/fixtures)
17
+ # * :logdev is a Logger log device used for general logging (default: nil)
9
18
  def init(local_root, options = {})
10
19
  db_init options
11
20
  earth_init(options[:earth])
@@ -22,10 +31,18 @@ module Sniff
22
31
  environments.each { |e| e.populate_fixtures }
23
32
  end
24
33
 
34
+ # Used within an emitter's custom schema definition - aggregates muliple
35
+ # schemas into a single schema generation transaction.
36
+ #
37
+ # Instead of:
38
+ # <tt>ActiveRecord::Schema.define(:version => XYZ) do</tt>
39
+ # It's:
40
+ # <tt>Sniff::Database.define_schema do</tt>
25
41
  def define_schema(&blk)
26
42
  schemas << blk
27
43
  end
28
44
 
45
+ # The list of schemas that have been loaded via define_schema
29
46
  def schemas
30
47
  @schemas = [] unless defined?(@schemas)
31
48
  @schemas
@@ -38,12 +55,15 @@ module Sniff
38
55
  db
39
56
  end
40
57
 
58
+ # Connect to the database and set up an ActiveRecord logger
41
59
  def db_init(options)
42
60
  ActiveRecord::Base.logger = Logger.new options[:sqllogdev]
43
61
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
44
62
  :database => ':memory:'
45
63
  end
46
64
 
65
+ # Initialize Earth, tell it to load schemas defined by each domain model's
66
+ # data_miner definition
47
67
  def earth_init(domains)
48
68
  domains ||= :none
49
69
  domains = [domains] unless domains.is_a? Array
@@ -53,6 +73,7 @@ module Sniff
53
73
  Earth.init *args
54
74
  end
55
75
 
76
+ # Apply defined schemas to database
56
77
  def load_all_schemas
57
78
  orig_std_out = STDOUT.clone
58
79
  STDOUT.reopen File.open(File.join('/tmp', 'schema_output'), 'w')
data/lib/sniff/tasks.rb CHANGED
@@ -1,8 +1,3 @@
1
- task :environment do
2
- ENV['SCHEMA'] = File.join Sniff.root, 'db', 'schema.rb'
3
- ENV['FIXTURES_PATH'] = File.join Sniff.root, 'test', 'fixtures'
4
- end
5
-
6
1
  task :console do
7
2
  require 'sniff'
8
3
  cwd = Dir.pwd
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sniff
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 15
10
- version: 0.0.15
9
+ - 17
10
+ version: 0.0.17
11
11
  platform: ruby
12
12
  authors:
13
13
  - Derek Kastner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-23 00:00:00 -04:00
18
+ date: 2010-07-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -93,12 +93,12 @@ dependencies:
93
93
  requirements:
94
94
  - - "="
95
95
  - !ruby/object:Gem::Version
96
- hash: 7
96
+ hash: 3
97
97
  segments:
98
98
  - 0
99
99
  - 0
100
- - 12
101
- version: 0.0.12
100
+ - 14
101
+ version: 0.0.14
102
102
  requirement: *id005
103
103
  - !ruby/object:Gem::Dependency
104
104
  type: :runtime
@@ -220,66 +220,7 @@ dependencies:
220
220
  - 4
221
221
  version: 0.0.4
222
222
  requirement: *id013
223
- description: |
224
- # sniff
225
- Development environment for Brighter Planet emitters.
226
-
227
- ## Background
228
- Brighter Planet's emitters, such as [`flight`](http://github.com/brighterplanet/flight), inhabit a complex production runtime environment backing its [emission estimates web service](http://carbon.brighterplanet.com). Sniff simulates this environment, including representative data, fixtures, and other supporting code, so that developers can test improvements to the emitters before submitting them back to Brighter Planet.
229
-
230
- ### Caution
231
- The data and other supporting information in the sniff environment is only representative of production data and in many cases is purely fictional, contrived to return predictable results in tests. Emission estimates and other information gleaned from execution within this environment will undoubtedly be--to put it simply--wrong. For real numbers, always use live queries to the [emission estimate web service](http://carbon.brighterplanet.com).
232
-
233
- ## Usage
234
- Sniff is never used directly but rather as a requirement of a specific emitter. Current production emitters include, for example:
235
-
236
- * [Automobile](http://github.com/brighterplanet/automobile)
237
- * [Flight](http://github.com/brighterplanet/flight)
238
- * [Residence](http://github.com/brighterplanet/residence)
239
-
240
- For a complete list, see the emission estimate service's [documentation](http://carbon.brighterplanet.com/use).
241
-
242
- ## The emitter
243
- An emitter is a software model of a real-world emission source, like a flight. Brighter Planet's emitter libraries each comprise a carbon model, an attribute curation policy, a persistence schema, and a summarization strategy.
244
-
245
- ### Persistence schema
246
- Although the production environment does not persist emitter instances, we nevertheless define emitter schemas to enable ActiveRecord assocations. An emitter's schema is defined in `lib/*emitter_name*/data.rb` within an emitter library. For example, here is [flight's schema](http://github.com/brighterplanet/flight/blob/master/lib/flight/data.rb).
247
-
248
- Schema are defined using a DSL provided by the [data_miner](http://github.com/seamusabshere/data_miner) library.
249
-
250
- ### Attribute curation policy
251
- This defines how an emitter's attributes (initialized and stored with respect to the schema) are curated and decorated into a snapshot for later use by the carbon model. The policy is defined in `lib/*emitter_name*/characterization.rb` within an emitter library. For example, here is [flight's characterization](http://github.com/brighterplanet/flight/blob/master/lib/flight/characterization.rb).
252
-
253
- Characterizations are defined using a DSL provided by the [characterizable](http://github.com/seamusabshere/characterizable) library.
254
-
255
- ### Carbon model
256
- An emission estimate is obtained by giving an emitter's curated characteristics as input to an execution of its carbon model. The model is defined in `lib/*emitter_name*/characterization.rb` within an emitter library. For example, here is [flight's carbon model](http://github.com/brighterplanet/flight/blob/master/lib/flight/carbon_model.rb).
257
-
258
- Carbon models are defined using a DSL provided by the [leap](http://github.com/rossmeissl/leap) library.
259
-
260
- ### Summarization strategy
261
- Summaries are human-friendly descriptions of characterized emitters. The strategy is defined in `lib/*emitter_name*/summarization.rb` within an emitter library. For example, here is [flight's summarization strategy](http://github.com/brighterplanet/flight/blob/master/lib/flight/summarization.rb).
262
-
263
- Summarizations are defined using a DSL provided by the [summary_judgement](http://github.com/rossmeissl/summary_judgement) library.
264
-
265
- ## Collaboration cycle
266
- Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.
267
-
268
- ### You
269
- 1. Fork the emitter repository on GitHub.
270
- 1. Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
271
- 1. Improve the code until your new test passes and commit your changes.
272
- 1. Push your changes to your GitHub fork.
273
- 1. Submit a pull request to brighterplanet.
274
-
275
- ### Brighter Planet
276
- 1. Receive a pull request.
277
- 1. Pull changes from forked repository.
278
- 1. Ensure tests pass.
279
- 1. Review changes for scientific accuracy.
280
- 1. Merge changes to master repository and publish.
281
- 1. Direct production environment to use new emitter version.
282
-
223
+ description: Provides data environment for emitter gems
283
224
  email: derek.kastner@brighterplanet.com
284
225
  executables: []
285
226