Class: AutoConfig::Base
- Inherits:
-
Object
- Object
- AutoConfig::Base
- Defined in:
- lib/autoconfig.rb
Class Method Summary collapse
- .autoload ⇒ Object (also: reload)
- .environment ⇒ Object
- .ignored_filenames ⇒ Object
- .load(name) ⇒ Object
- .path ⇒ Object
- .pattern ⇒ Object
- .rails? ⇒ Boolean
- .root ⇒ Object
Class Method Details
.autoload ⇒ Object Also known as: reload
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/autoconfig.rb', line 49 def autoload wipe files = Dir.glob(File.join(path,pattern)) begin old_verbose, $VERBOSE = $VERBOSE, nil files.each do |file| name = File.basename(file, pattern.gsub('*','')) next if name.match(ignored_filenames) || name.match(/-overrides/) constant_name = "#{name}Config".gsub('-','_').camelize.intern begin Object::const_set(constant_name, load(name)) @autoset_constants ||= Set.new @autoset_constants << constant_name rescue StandardError => e @errors << <<-ERROR Error reading file #{file} into #{constant_name}. #{$!.inspect} #{$@} You can skip it by adding it to AUTOCONFIG_IGNORE. ERROR end end raise @errors.to_a.join( "\n" ) unless @errors.empty? ensure $VERBOSE = old_verbose end end |
.environment ⇒ Object
31 32 33 |
# File 'lib/autoconfig.rb', line 31 def environment ENV['AUTOCONFIG_ENV'] || ENV['APP_ENV'] || (rails? && Rails.env) || 'development' end |
.ignored_filenames ⇒ Object
39 40 41 42 |
# File 'lib/autoconfig.rb', line 39 def ignored_filenames names = ENV['AUTOCONFIG_IGNORE'] ? "database|" + ENV['AUTOCONFIG_IGNORE'].gsub(/\s/,'|') : 'database' Regexp.new(names) end |
.load(name) ⇒ Object
44 45 46 |
# File 'lib/autoconfig.rb', line 44 def load(name) HierarchicalConfig.load_config( name, path, environment ) end |
.path ⇒ Object
27 28 29 |
# File 'lib/autoconfig.rb', line 27 def path ENV['AUTOCONFIG_PATH'] || File.('config',root) end |
.pattern ⇒ Object
23 24 25 |
# File 'lib/autoconfig.rb', line 23 def pattern ENV['AUTOCONFIG_PATTERN'] || '*.yml' end |
.rails? ⇒ Boolean
35 36 37 |
# File 'lib/autoconfig.rb', line 35 def rails? Object::const_defined? "Rails" end |
.root ⇒ Object
18 19 20 21 |
# File 'lib/autoconfig.rb', line 18 def root rails_root = (rails? && (Rails.root || File.('../', ENV['BUNDLE_GEMFILE']))) ENV['AUTOCONFIG_ROOT'] || ENV['APP_ROOT'] || rails_root || Dir.pwd end |