earth 0.2.11 → 0.2.12

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.
Files changed (4) hide show
  1. data/Gemfile.lock +1 -1
  2. data/lib/earth.rb +24 -4
  3. data/spec/earth_spec.rb +43 -12
  4. metadata +2 -2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- earth (0.2.7)
4
+ earth (0.2.11)
5
5
  activerecord (>= 3.0.0.beta4)
6
6
  cohort_scope (>= 0.0.7)
7
7
  conversions (>= 1.4.5)
@@ -31,9 +31,14 @@ module Earth
31
31
  # Default is search all domains
32
32
  # For example, <tt>[ 'Aircraft', 'Airline' ]</tt>
33
33
  def resource_names(search_domains = nil)
34
- (search_domains || domains).map do |domain|
35
- Dir[File.join(Earth.gem_root, 'lib', 'earth', domain, '*.rb')]
36
- end.flatten.uniq.map { |p| File.basename(p, '.rb').camelcase } - %w{ DataMiner }
34
+ if search_domains.nil?
35
+ resources.keys
36
+ else
37
+ resources.inject([]) do |list, (name, data)|
38
+ list << name if search_domains.include? data[:domain]
39
+ list
40
+ end
41
+ end
37
42
  end
38
43
 
39
44
  def gem_root
@@ -41,7 +46,22 @@ module Earth
41
46
  end
42
47
 
43
48
  def domains
44
- %w{air automobile bus diet fuel locality pet rail residence}
49
+ @domains ||= resources.map { |(name, data)| data[:domain] }.uniq.sort
50
+ end
51
+
52
+ def resources
53
+ return @resources unless @resources.nil?
54
+ earth_files = Dir[File.join(Earth.gem_root, 'lib', 'earth', '*')]
55
+ domain_dirs = earth_files.find_all { |f| File.directory?(f) }
56
+ @resources = domain_dirs.inject({}) do |hsh, domain_dir|
57
+ Dir[File.join(domain_dir, '*.rb')].each do |resource_file|
58
+ resource_camel = File.basename(resource_file, '.rb').camelcase
59
+ unless resource_camel == 'DataMiner'
60
+ hsh[resource_camel] = { :domain => File.basename(domain_dir) }
61
+ end
62
+ end
63
+ hsh
64
+ end
45
65
  end
46
66
 
47
67
  # Earth.init will load any specified domains, any needed ActiveRecord plugins,
@@ -1,25 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Earth do
4
- before :all do
5
- Earth.init :all, :apply_schemas => true
4
+ describe '.init' do
5
+ before :all do
6
+ Earth.init :all, :apply_schemas => true
7
+ end
8
+
9
+ it 'should require all Earth models' do
10
+ lambda do
11
+ Earth.resource_names.each { |k| k.constantize }
12
+ end.should_not raise_error(NameError)
13
+ end
14
+
15
+ it 'should include data_miner definitions' do
16
+ lambda do
17
+ Earth.resource_names.each { |k| k.constantize.should_receive(:data_miner) }
18
+ end
19
+ require 'earth/data_miner'
20
+ end
21
+
22
+ it 'should create a fallbacks table' do
23
+ Fallback.should be_table_exists
24
+ end
6
25
  end
7
26
 
8
- it 'should require all Earth models' do
9
- lambda do
10
- Earth.resource_names.each { |k| k.constantize }
11
- end.should_not raise_error(NameError)
27
+ describe '.resources' do
28
+ it 'should get a list of resources' do
29
+ resources = Earth.resources
30
+ resources.keys.count.should == 56
31
+ resources['FuelType'][:domain].should == 'fuel'
32
+ end
33
+ it 'should exclude data_miner files' do
34
+ Earth.resources.keys.should_not include('DataMiner')
35
+ end
12
36
  end
13
37
 
14
- it 'should include data_miner definitions' do
15
- lambda do
16
- Earth.resource_names.each { |k| k.constantize.should_receive(:data_miner) }
38
+ describe '.resource_names' do
39
+ it 'should get a list of all resource names' do
40
+ Earth.resource_names.count.should == 56
41
+ Earth.resource_names.should include('Aircraft')
42
+ Earth.resource_names.should include('Industry')
43
+ end
44
+ it 'should filter resources by domain' do
45
+ Earth.resource_names(['fuel']).count.should == 2
46
+ Earth.resource_names(['fuel']).should include('FuelType')
17
47
  end
18
- require 'earth/data_miner'
19
48
  end
20
49
 
21
- it 'should create a fallbacks table' do
22
- Fallback.should be_table_exists
50
+ describe '.domains' do
51
+ it 'should return a list of all domains' do
52
+ Earth.domains.should == %w{air automobile bus diet fuel hospitality industry locality pet rail residence}
53
+ end
23
54
  end
24
55
  end
25
56
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 11
9
- version: 0.2.11
8
+ - 12
9
+ version: 0.2.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Seamus Abshere