module Earth
The earth module is an interface for loading data models
Constants
- DATA_DIR
- ERRATA_DIR
- FACTORY_DIR
- LIB_DIR
- VENDOR_DIR
- VERSION
Public Class Methods
Connect to the database using ActiveRecord’s default behavior
# File lib/earth.rb, line 72 def Earth.connect ActiveRecord::Base.establish_connection ActiveRecord::Base.connection end
The current environment. Earth
detects the following environment variables:
-
EARTH_ENV (for CLI apps and daemons)
-
RAILS_ENV
-
RACK_ENV
Default is ‘development`
# File lib/earth.rb, line 84 def Earth.env @env ||= ActiveSupport::StringInquirer.new(ENV['EARTH_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development') end
Earth.init
is the gateway to using Earth
. It can load all models at once, connect to the database using Rails conventions, and set up the models to pull data from original sources instead of Brighter Planet’s pre-processed data service.
@param [Symbol] load_directive use ‘:all` to load all models at once (optional) @param [Hash] options load options
-
:mine_original_sources, if true, will load files necessary to data mine from scratch rather than downloading from data.brighterplanet.com. Note that you must run
Earth.init
before requiring models in order for this option to work properly. -
:connect will connect to the database for you
# File lib/earth.rb, line 37 def Earth.init(*args) options = args.extract_options! if options[:connect] connect Warnings.check_mysql_ansi_mode end Earth.mine_original_sources = options[:load_data_miner] || options[:mine_original_sources] if args.include? :all require 'earth/all' elsif args.length > 0 Kernel.warn "Deprecation Warning: `Earth.init :domain` will be removed. Use `require 'earth/domain'` instead" args.each do |argh| require "earth/#{argh}" end end end
Drop and recreate tables for all currently loaded data models.
# File lib/earth.rb, line 90 def Earth.reset_schemas! Earth.resource_models.each(&:create_table!) end
List the currently loaded data model classes
@return [Array] a list of resource classes
# File lib/earth.rb, line 67 def Earth.resource_models Earth::Model.registry end
List the currently loaded data model class names.
@return [Array] a list of camelized resource names
# File lib/earth.rb, line 60 def Earth.resources @resources ||= Earth.resource_models.map(&:to_s).sort end
Run data miner on all currently loaded data models.
@note By default, data is mined from data.brighterplanet.com via taps. In order to mine from scratch, call Earth.init
with the :mine_original_sources option.
# File lib/earth.rb, line 99 def Earth.run_data_miner! DataMiner.run(Earth.resources) end