Module: LoadRails
- Defined in:
- lib/load_rails.rb,
lib/load_rails/version.rb,
lib/load_rails/exceptions/rails_not_found.rb
Defined Under Namespace
Classes: RailsNotFound
Constant Summary collapse
- RAILS_ENVIRONMENT_PATH =
::File.join("config", "environment.rb").freeze
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.environment? ⇒ Boolean
Determines if the current directory is the root of a Rails project.
-
.load ⇒ nil
Finds the closes Rails application and requires it.
-
.parent! ⇒ nil
Attempts to change directories to the parent of the current directory.
-
.require_rails! ⇒ nil
Uses Ruby
requireto require the Rails environment for the current directory.
Class Method Details
.environment? ⇒ Boolean
Determines if the current directory is the root of a Rails project.
13 14 15 |
# File 'lib/load_rails.rb', line 13 def self.environment? File.exist?(RAILS_ENVIRONMENT_PATH) end |
.load ⇒ nil
Finds the closes Rails application and requires it.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/load_rails.rb', line 19 def self.load loop do if environment? require_rails! break else parent! end end end |
.parent! ⇒ nil
Attempts to change directories to the parent of the current directory
35 36 37 38 39 40 |
# File 'lib/load_rails.rb', line 35 def self.parent! current_directory = Dir.pwd FileUtils.cd("..") raise RailsNotFound if current_directory == Dir.pwd end |
.require_rails! ⇒ nil
Uses Ruby require to require the Rails environment for the current directory.
45 46 47 48 |
# File 'lib/load_rails.rb', line 45 def self.require_rails! require(::File.(RAILS_ENVIRONMENT_PATH, Dir.pwd)) Rails.application.eager_load! end |