Class: Environmenter::Loader
- Inherits:
-
Object
- Object
- Environmenter::Loader
- Defined in:
- lib/environmenter/loader.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config = nil) ⇒ Loader
constructor
A new instance of Loader.
- #load! ⇒ Object
- #load_rails ⇒ Object
- #require_from_config ⇒ Object
- #set_environment ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Loader
Returns a new instance of Loader.
5 6 7 |
# File 'lib/environmenter/loader.rb', line 5 def initialize(config = nil) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/environmenter/loader.rb', line 3 def config @config end |
Instance Method Details
#load! ⇒ Object
9 10 11 12 13 |
# File 'lib/environmenter/loader.rb', line 9 def load! set_environment load_rails require_from_config end |
#load_rails ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/environmenter/loader.rb', line 20 def load_rails begin require 'rails' if ::Rails.application.respond_to?(:eager_load) require File.('config/environment.rb') ::Rails.application.eager_load! else require File.('config/application.rb') ::Rails::Application.initializer "lapine.load_rails" do ::Rails.application.config.eager_load = true end require File.('config/environment.rb') end rescue LoadError end end |
#require_from_config ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/environmenter/loader.rb', line 37 def require_from_config return unless config if config.respond_to?(:require) && config.require return config.require.each do |file| require File.(file) end end if config.respond_to?(:[]) if config['require'] return config['require'].each do |file| require File.(file) end end if config[:require] return config[:require].each do |file| require File.(file) end end end end |
#set_environment ⇒ Object
15 16 17 18 |
# File 'lib/environmenter/loader.rb', line 15 def set_environment ENV['RAILS_ENV'] ||= 'development' ENV['RACK_ENV'] ||= ENV['RAILS_ENV'] end |