sniff 0.1.17 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,28 +26,9 @@ module Sniff
26
26
  environments << init_environment(Sniff.root)
27
27
  end
28
28
 
29
- load_all_schemas
30
-
31
29
  environments.each { |e| e.populate_fixtures }
32
30
  end
33
31
 
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>
41
- def define_schema(&blk)
42
- schemas << blk
43
- end
44
-
45
- # The list of schemas that have been loaded via define_schema
46
- def schemas
47
- @schemas = [] unless defined?(@schemas)
48
- @schemas
49
- end
50
-
51
32
  private
52
33
  def init_environment(root, options = {})
53
34
  db = new root, options
@@ -72,21 +53,6 @@ module Sniff
72
53
 
73
54
  Earth.init *args
74
55
  end
75
-
76
- # Apply defined schemas to database
77
- def load_all_schemas
78
- orig_std_out = STDOUT.clone
79
- STDOUT.reopen File.open(File.join('/tmp', 'schema_output'), 'w')
80
-
81
- ActiveRecord::Schema.define(:version => 1) do
82
- ar_schema = self
83
- Sniff::Database.schemas.each do |s|
84
- ar_schema.instance_eval &s
85
- end
86
- end
87
- ensure
88
- STDOUT.reopen(orig_std_out)
89
- end
90
56
  end
91
57
 
92
58
  attr_accessor :root, :lib_path, :fixtures_path,
@@ -109,10 +75,6 @@ module Sniff
109
75
  @load_data
110
76
  end
111
77
 
112
- def schema_path
113
- @schema_path ||= File.join(lib_path, 'db', 'schema.rb')
114
- end
115
-
116
78
  def fixtures_path
117
79
  @fixtures_path ||= File.join(lib_path, 'db', 'fixtures')
118
80
  end
@@ -123,13 +85,22 @@ module Sniff
123
85
 
124
86
  def init
125
87
  load_supporting_libs
126
- read_schema
88
+ create_emitter_table
127
89
  read_fixtures if load_data?
128
90
  end
129
91
 
130
- def read_schema
131
- log "Reading schema #{schema_path}"
132
- load(schema_path) if File.exist?(schema_path)
92
+ def emitter_class
93
+ return @emitter_class unless @emitter_class.nil?
94
+ record_class_file = Dir.glob(File.join(root, 'lib', 'test_support', '*_record.rb')).first
95
+ if record_class_file
96
+ record_class = File.read(record_class_file)
97
+ klass = record_class.scan(/class ([^\s]*Record)/).flatten.first
98
+ @emitter_class = klass.constantize
99
+ end
100
+ end
101
+
102
+ def create_emitter_table
103
+ emitter_class.execute_schema if emitter_class
133
104
  end
134
105
 
135
106
  def read_fixtures
@@ -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,17 @@
1
+ require 'conversions'
2
+
3
+ module BrighterPlanet
4
+ module Dirigible
5
+ module CarbonModel
6
+ def self.included(base)
7
+ base.decide :emission, :with => :characteristics do
8
+ committee :emission do # returns kg CO2
9
+ quorum 'default' do
10
+ 100.0
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module BrighterPlanet
2
+ module Dirigible
3
+ module Characterization
4
+ def self.included(base)
5
+ base.characterize do
6
+ has :make
7
+ has :annual_distance_estimate, :measures => :length
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module BrighterPlanet
2
+ module Dirigible
3
+ module Data
4
+ def self.included(base)
5
+ base.data_miner do
6
+ schema do
7
+ float 'fuel_efficiency'
8
+ float 'annual_distance_estimate'
9
+ end
10
+
11
+ process :run_data_miner_on_belongs_to_associations
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module BrighterPlanet
2
+ module Dirigible
3
+ module Summarization
4
+ def self.included(base)
5
+ base.summarize do |has|
6
+ has.adjective :model_year
7
+ has.adjective :make
8
+ has.adjective :model
9
+ has.verb :own
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+ require 'falls_back_on'
3
+ require 'dirigible'
4
+ require 'sniff'
5
+
6
+ class DirigibleRecord < ActiveRecord::Base
7
+ include BrighterPlanet::Dirigible
8
+ include Sniff::Emitter
9
+
10
+ falls_back_on :fuel_efficiency => 20.182.miles_per_gallon.to(:kilometres_per_litre), # mpg https://brighterplanet.sifterapp.com/projects/30/issues/428
11
+ :annual_distance_estimate => 11819.miles.to(:kilometres) # miles https://brighterplanet.sifterapp.com/projects/30/issues/428
12
+ end
@@ -3,19 +3,25 @@ require 'fileutils'
3
3
 
4
4
  describe Sniff::Database do
5
5
  describe '#connect' do
6
+ let(:dirigible_path) { File.expand_path '../../fixtures/dirigible', File.dirname(__FILE__) }
7
+
6
8
  before :each do
7
- @db_path = File.join(File.dirname(__FILE__), '..', '..', '..')
9
+ require File.join(dirigible_path, 'lib', 'dirigible')
8
10
  end
11
+
9
12
  it 'should load the air domain' do
10
- Sniff.init(@db_path, :earth => :air, :apply_schemas => true)
13
+ Sniff.init(dirigible_path, :earth => :air, :apply_schemas => true)
11
14
  Airport.count.should == 0 # we don't have fixtures for this here
12
15
  ZipCode.count.should > 0
13
16
  expect { AutomobileFuelType }.should raise_error
14
17
  end
15
18
  it 'should load data for all domains' do
16
- Sniff.init(@db_path, :earth => :all, :apply_schemas => true)
19
+ Sniff.init(dirigible_path, :earth => :all, :apply_schemas => true)
17
20
  ZipCode.count.should > 0
18
21
  end
22
+ it 'should load a schema for the emitter record' do
23
+ DirigibleRecord.table_exists?.should be_true
24
+ end
19
25
  end
20
26
  end
21
27
 
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: 57
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 17
10
- version: 0.1.17
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
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-09-21 00:00:00 -04:00
18
+ date: 2010-09-23 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -163,7 +163,7 @@ dependencies:
163
163
  - !ruby/object:Gem::Dependency
164
164
  type: :development
165
165
  prerelease: false
166
- name: jeweler
166
+ name: emitter
167
167
  version_requirements: &id010 !ruby/object:Gem::Requirement
168
168
  none: false
169
169
  requirements:
@@ -177,7 +177,7 @@ dependencies:
177
177
  - !ruby/object:Gem::Dependency
178
178
  type: :development
179
179
  prerelease: false
180
- name: rake
180
+ name: jeweler
181
181
  version_requirements: &id011 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
@@ -191,7 +191,7 @@ dependencies:
191
191
  - !ruby/object:Gem::Dependency
192
192
  type: :development
193
193
  prerelease: false
194
- name: rcov
194
+ name: rake
195
195
  version_requirements: &id012 !ruby/object:Gem::Requirement
196
196
  none: false
197
197
  requirements:
@@ -205,7 +205,7 @@ dependencies:
205
205
  - !ruby/object:Gem::Dependency
206
206
  type: :development
207
207
  prerelease: false
208
- name: rdoc
208
+ name: rcov
209
209
  version_requirements: &id013 !ruby/object:Gem::Requirement
210
210
  none: false
211
211
  requirements:
@@ -219,8 +219,22 @@ dependencies:
219
219
  - !ruby/object:Gem::Dependency
220
220
  type: :development
221
221
  prerelease: false
222
- name: rspec
222
+ name: rdoc
223
223
  version_requirements: &id014 !ruby/object:Gem::Requirement
224
+ none: false
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ hash: 3
229
+ segments:
230
+ - 0
231
+ version: "0"
232
+ requirement: *id014
233
+ - !ruby/object:Gem::Dependency
234
+ type: :development
235
+ prerelease: false
236
+ name: rspec
237
+ version_requirements: &id015 !ruby/object:Gem::Requirement
224
238
  none: false
225
239
  requirements:
226
240
  - - ~>
@@ -233,7 +247,7 @@ dependencies:
233
247
  - beta
234
248
  - 17
235
249
  version: 2.0.0.beta.17
236
- requirement: *id014
250
+ requirement: *id015
237
251
  description: Provides data environment for emitter gems
238
252
  email: derek.kastner@brighterplanet.com
239
253
  executables: []
@@ -262,6 +276,12 @@ files:
262
276
  - lib/test_support/db/fixtures/urbanities.csv
263
277
  - lib/test_support/db/fixtures/zip_codes.csv
264
278
  - README.markdown
279
+ - spec/fixtures/dirigible/lib/dirigible/carbon_model.rb
280
+ - spec/fixtures/dirigible/lib/dirigible/characterization.rb
281
+ - spec/fixtures/dirigible/lib/dirigible/data.rb
282
+ - spec/fixtures/dirigible/lib/dirigible/summarization.rb
283
+ - spec/fixtures/dirigible/lib/dirigible.rb
284
+ - spec/fixtures/dirigible/lib/test_support/dirigible_record.rb
265
285
  - spec/lib/sniff/database_spec.rb
266
286
  - spec/lib/test_support/cucumber/support/values_spec.rb
267
287
  - spec/spec_helper.rb
@@ -300,6 +320,12 @@ signing_key:
300
320
  specification_version: 3
301
321
  summary: Test support for Brighter Planet carbon gems
302
322
  test_files:
323
+ - spec/fixtures/dirigible/lib/dirigible/carbon_model.rb
324
+ - spec/fixtures/dirigible/lib/dirigible/characterization.rb
325
+ - spec/fixtures/dirigible/lib/dirigible/data.rb
326
+ - spec/fixtures/dirigible/lib/dirigible/summarization.rb
327
+ - spec/fixtures/dirigible/lib/dirigible.rb
328
+ - spec/fixtures/dirigible/lib/test_support/dirigible_record.rb
303
329
  - spec/lib/sniff/database_spec.rb
304
330
  - spec/lib/test_support/cucumber/support/values_spec.rb
305
331
  - spec/spec_helper.rb