Module: Earth

Extended by:
Earth
Included in:
Earth
Defined in:
lib/earth.rb,
lib/earth/base.rb

Overview

The earth module is an interface for establishing a taps server (used to fetch data) and for loading data models from various domains.

Defined Under Namespace

Modules: Base

Instance Method Summary collapse

Instance Method Details

#database_optionsObject



69
70
71
72
73
74
75
# File 'lib/earth.rb', line 69

def database_options
  if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
    {}
  else
    { :options => 'ENGINE=InnoDB default charset=utf8' }
  end
end

#domainsObject



41
42
43
# File 'lib/earth.rb', line 41

def domains
  %w{air automobile bus diet fuel locality pet rail residence}
end

#gem_rootObject



37
38
39
# File 'lib/earth.rb', line 37

def gem_root 
  File.expand_path File.join(File.dirname(__FILE__), '..')
end

#init(*args) ⇒ Object

Earth.init will load any specified domains, any needed ActiveRecord plugins, and will apply each domain model’s schema to the database if the :apply_schemas option is given. See Earth.domains for the list of allowable domains.

Earth.init should be performed after a connection is made to the database and before any domain models are referenced.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/earth.rb', line 52

def init(*args)
  load_plugins

  domains = []
  options = {}
  args.each do |arg|
    if arg.is_a?(Hash)
      options = arg
    else
      domains << arg
    end
  end

  load_domains(domains, options)
  load_schemas if options[:apply_schemas]
end

#resource_names(search_domains = nil) ⇒ Object

Takes argument like Earth.resource_names() Default is search all domains For example, [ 'Aircraft', 'Airline' ]



31
32
33
34
35
# File 'lib/earth.rb', line 31

def resource_names(search_domains = nil)
  (search_domains || domains).map do |domain|
    Dir[File.join(Earth.gem_root, 'lib', 'earth', domain, '*.rb')]
  end.flatten.uniq.map { |p| File.basename(p, '.rb').camelcase } - %w{ DataMiner }
end

#taps_serverObject



15
16
17
18
19
20
21
# File 'lib/earth.rb', line 15

def taps_server
  if defined?(@taps_server)
    @taps_server
  else
    @taps_server = nil
  end
end

#taps_server=(val) ⇒ Object

taps_server is a URL. See the data_miner gem docs



24
25
26
# File 'lib/earth.rb', line 24

def taps_server=(val)
  @taps_server = val
end