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



71
72
73
74
75
76
77
# File 'lib/earth.rb', line 71

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

#domainsObject



43
44
45
# File 'lib/earth.rb', line 43

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

#gem_rootObject



39
40
41
# File 'lib/earth.rb', line 39

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.



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

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' ]



33
34
35
36
37
# File 'lib/earth.rb', line 33

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



17
18
19
20
21
22
23
# File 'lib/earth.rb', line 17

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



26
27
28
# File 'lib/earth.rb', line 26

def taps_server=(val)
  @taps_server = val
end