Module: LokaliseRails::Utils
- Defined in:
- lib/lokalise_rails/utils.rb
Overview
Util methods
Class Method Summary collapse
-
.rails_root ⇒ String?
Attempts to determine the root directory of a Rails project by checking the presence of Rails and its root method.
-
.root ⇒ Pathname
Retrieves the root directory of the current project.
Class Method Details
.rails_root ⇒ String?
Attempts to determine the root directory of a Rails project by checking the presence of Rails and its root method. If Rails is older and does not have the root method, it falls back to the RAILS_ROOT constant if defined.
24 25 26 27 28 29 30 31 32 |
# File 'lib/lokalise_rails/utils.rb', line 24 def rails_root # First, check if Rails.root is defined and return its path if available. return ::Rails.root.to_s if defined?(::Rails.root) && ::Rails.root # Fallback to the RAILS_ROOT constant from older Rails versions. return RAILS_ROOT.to_s if defined?(RAILS_ROOT) # Returns nil if none of the above are defined, indicating Rails is not present. nil end |
.root ⇒ Pathname
Retrieves the root directory of the current project. It attempts to find the Rails root directory if Rails is loaded. If Rails is not present, it defaults to the current working directory of the process.
14 15 16 17 |
# File 'lib/lokalise_rails/utils.rb', line 14 def root # Uses Pathname to create a robust path object from the rails_root or the current working directory. Pathname.new(rails_root || Dir.getwd) end |