Module: Earth
- Defined in:
- lib/earth.rb,
lib/earth/eia.rb,
lib/earth/model.rb,
lib/earth/tasks.rb,
lib/earth/utils.rb,
lib/earth/loader.rb,
lib/earth/version.rb,
lib/earth/warnings.rb,
lib/earth/insolation_scopes.rb
Overview
The earth module is an interface for loading data models
Defined Under Namespace
Modules: EIA, InsolationScopes, Loader, Model, Utils, Warnings Classes: Tasks
Constant Summary collapse
- VENDOR_DIR =
::File. '../../vendor', __FILE__
- LIB_DIR =
::File. '../earth', __FILE__
- DATA_DIR =
::File. '../../data', __FILE__
- ERRATA_DIR =
::File. '../../errata', __FILE__
- FACTORY_DIR =
::File. '../../spec/factories', __FILE__
- VERSION =
"1.1.1"
Class Method Summary collapse
-
.connect ⇒ Object
Connect to the database using ActiveRecord’s default behavior.
-
.env ⇒ Object
The current environment.
-
.init(*args) ⇒ Object
Earth.init is the gateway to using Earth.
-
.reset_schemas! ⇒ Object
Drop and recreate tables for all currently loaded data models.
-
.resource_models ⇒ Array
List the currently loaded data model classes.
-
.resources ⇒ Array
List the currently loaded data model class names.
-
.run_data_miner! ⇒ Object
Run data miner on all currently loaded data models.
Class Method Details
.connect ⇒ Object
Connect to the database using ActiveRecord’s default behavior
72 73 74 75 |
# File 'lib/earth.rb', line 72 def Earth.connect ActiveRecord::Base.establish_connection ActiveRecord::Base.connection end |
.env ⇒ Object
The current environment. Earth detects the following environment variables:
-
EARTH_ENV (for CLI apps and daemons)
-
RAILS_ENV
-
RACK_ENV
Default is ‘development`
84 85 86 |
# File 'lib/earth.rb', line 84 def Earth.env @env ||= ActiveSupport::StringInquirer.new(ENV['EARTH_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development') end |
.init(*args) ⇒ Object
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.
-
: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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/earth.rb', line 37 def Earth.init(*args) = args. if [:connect] connect Warnings.check_mysql_ansi_mode end Earth.mine_original_sources = [:load_data_miner] || [: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 |
.reset_schemas! ⇒ Object
Drop and recreate tables for all currently loaded data models.
90 91 92 |
# File 'lib/earth.rb', line 90 def Earth.reset_schemas! Earth.resource_models.each(&:create_table!) end |
.resource_models ⇒ Array
List the currently loaded data model classes
67 68 69 |
# File 'lib/earth.rb', line 67 def Earth.resource_models Earth::Model.registry end |
.resources ⇒ Array
List the currently loaded data model class names.
60 61 62 |
# File 'lib/earth.rb', line 60 def Earth.resources @resources ||= Earth.resource_models.map(&:to_s).sort end |
.run_data_miner! ⇒ Object
By default, data is mined from data.brighterplanet.com
Run data miner on all currently loaded data models.
via taps. In order to mine from scratch, call Earth.init with the :mine_original_sources option.
99 100 101 |
# File 'lib/earth.rb', line 99 def Earth.run_data_miner! DataMiner.run(Earth.resources) end |