Module: Earth
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
- #database_options ⇒ Object
- #domains ⇒ Object
- #gem_root ⇒ Object
-
#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.
-
#resource_names(search_domains = nil) ⇒ Object
Takes argument like Earth.resource_names() Default is search all domains For example,
[ 'Aircraft', 'Airline' ]
. - #resources ⇒ Object
- #taps_server ⇒ Object
-
#taps_server=(val) ⇒ Object
taps_server is a URL.
Instance Method Details
#database_options ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/earth.rb', line 87 def if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite' {} else { :options => 'ENGINE=InnoDB default charset=utf8' } end end |
#domains ⇒ Object
44 45 46 |
# File 'lib/earth.rb', line 44 def domains @domains ||= resources.map { |(name, data)| data[:domain] }.uniq.sort end |
#gem_root ⇒ Object
40 41 42 |
# File 'lib/earth.rb', line 40 def gem_root File. 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/earth.rb', line 70 def init(*args) load_plugins domains = [] = {} args.each do |arg| if arg.is_a?(Hash) = arg else domains << arg end end load_domains(domains, ) load_schemas if [:apply_schemas] end |
#resource_names(search_domains = nil) ⇒ Object
Takes argument like Earth.resource_names() Default is search all domains For example, [ 'Aircraft', 'Airline' ]
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/earth.rb', line 29 def resource_names(search_domains = nil) if search_domains.nil? resources.keys else resources.inject([]) do |list, (name, data)| list << name if search_domains.include? data[:domain] list end end end |
#resources ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/earth.rb', line 48 def resources return @resources unless @resources.nil? earth_files = Dir[File.join(Earth.gem_root, 'lib', 'earth', '*')] domain_dirs = earth_files.find_all { |f| File.directory?(f) } @resources = domain_dirs.inject({}) do |hsh, domain_dir| Dir[File.join(domain_dir, '*.rb')].each do |resource_file| resource_camel = File.basename(resource_file, '.rb').camelcase unless resource_camel == 'DataMiner' hsh[resource_camel] = { :domain => File.basename(domain_dir) } end end hsh end end |
#taps_server ⇒ Object
17 18 19 |
# File 'lib/earth.rb', line 17 def taps_server @taps_server || 'http://carbon:[email protected]:5001' end |
#taps_server=(val) ⇒ Object
taps_server is a URL. See the data_miner gem docs
22 23 24 |
# File 'lib/earth.rb', line 22 def taps_server=(val) @taps_server = val end |