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.
- data/Gemfile.lock +1 -1
- data/lib/earth.rb +24 -4
- data/spec/earth_spec.rb +43 -12
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/earth.rb
CHANGED
@@ -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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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,
|
data/spec/earth_spec.rb
CHANGED
@@ -1,25 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Earth do
|
4
|
-
|
5
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
15
|
-
|
16
|
-
Earth.resource_names.
|
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
|
-
|
22
|
-
|
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
|
|