Module: LokaliseRails::Utils
- Defined in:
- lib/lokalise_rails/utils.rb
Overview
Utility methods for LokaliseRails
Class Method Summary collapse
-
.rails_root ⇒ Pathname?
Returns the root directory of a Rails application, if present.
- .require_config! ⇒ Object
-
.root ⇒ Pathname
Returns the root directory of the current project.
Class Method Details
.rails_root ⇒ Pathname?
Returns the root directory of a Rails application, if present.
- Uses
Rails.rootwhen Rails is loaded. - Returns
nilwhen Rails is not available.
25 26 27 |
# File 'lib/lokalise_rails/utils.rb', line 25 def rails_root ::Rails.root if defined?(::Rails) && ::Rails.respond_to?(:root) end |
.require_config! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lokalise_rails/utils.rb', line 29 def require_config! config_path = root.join('config', 'lokalise_rails.rb') unless config_path.exist? abort <<~MSG LokaliseRails configuration file was not found at #{config_path}. Run `rails generate lokalise_rails:install` first. MSG end require config_path.to_s end |
.root ⇒ Pathname
Returns the root directory of the current project.
If Rails is available, this returns Rails.root.
Otherwise, it falls back to the current working directory.
15 16 17 |
# File 'lib/lokalise_rails/utils.rb', line 15 def root rails_root || Pathname.pwd end |