Module: Earth
- Defined in:
- lib/earth.rb,
lib/earth/eia.rb,
lib/earth/utils.rb,
lib/earth/version.rb,
lib/earth/active_record_base_class_methods.rb
Overview
The earth module is an interface for loading data models from various domains.
Defined Under Namespace
Modules: ActiveRecordBaseClassMethods, EIA, Utils
Constant Summary collapse
- VERSION =
"0.12.4"
- TAPS_SOURCE =
'http://carbon:[email protected]:5000'
- TAPS_DESCRIPTION =
"Brighter Planet's reference data web service"
- VENDOR_DIR =
::File. '../../vendor', __FILE__
- LIB_DIR =
::File. '../earth', __FILE__
- DATA_DIR =
::File. '../../data', __FILE__
- ERRATA_DIR =
::File. '../../errata', __FILE__
Class Method Summary collapse
- .domains ⇒ 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.
-
.require_all(options = {}) ⇒ Object
internal use.
-
.require_related(path) ⇒ Object
internal use.
- .resources(*search_domains) ⇒ Object
Class Method Details
.domains ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/earth.rb', line 28 def Earth.domains @domains ||= ::Dir[::File.join(LIB_DIR, '*')].map do |path| if ::File.directory? path ::File.basename path end end.compact.uniq.sort 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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/earth.rb', line 57 def Earth.init(*args) = args. domains = args warn_unless_mysql_ansi_mode load_plugins if domains.include?(:none) # don't load anything elsif domains.include?(:all) or domains.empty? require_all else domains.each do |domain| require_domain domain, end end # be sure to look at both explicitly and implicitly loaded resources resources.select do |resource| ::Object.const_defined?(resource) end.each do |resource| resource_model = resource.constantize unless [:skip_parent_associations] resource_model.data_miner_script.append_once :process, :run_data_miner_on_parent_associations! end if [:load_data_miner] resource_model.data_miner_script.prepend_once :process, :auto_upgrade! else resource_model.data_miner_script.prepend_once :tap, TAPS_DESCRIPTION, TAPS_SOURCE end if [:apply_schemas] resource_model.auto_upgrade! end end end |
.require_all(options = {}) ⇒ Object
internal use
102 103 104 |
# File 'lib/earth.rb', line 102 def Earth.require_all( = {}) require_glob ::File.join(LIB_DIR, '**', '*.rb'), end |
.require_related(path) ⇒ Object
internal use
94 95 96 97 98 99 |
# File 'lib/earth.rb', line 94 def Earth.(path) path = ::File. path raise ::ArgumentError, %{[earth gem] #{path} is not in #{LIB_DIR}} unless path.start_with?(LIB_DIR) domain = %r{#{LIB_DIR}/([^\./]+)}.match(path).captures.first require_domain domain, :load_data_miner => path.include?('data_miner') end |
.resources(*search_domains) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/earth.rb', line 36 def Earth.resources(*search_domains) search_domains = search_domains.flatten.compact.map(&:to_s) if search_domains.empty? search_domains = domains end search_domains.map do |domain| ::Dir[::File.join(LIB_DIR, domain, '**', '*.rb')].map do |possible_resource| unless possible_resource.include?('data_miner') ::File.basename(possible_resource, '.rb').camelcase end end end.flatten.compact.sort end |