Module: LokaliseRails::Utils

Defined in:
lib/lokalise_rails/utils.rb

Overview

Utility methods for LokaliseRails

Class Method Summary collapse

Class Method Details

.rails_rootPathname?

Returns the root directory of a Rails application, if present.

  • Uses Rails.root when Rails is loaded.
  • Returns nil when Rails is not available.

Returns:

  • (Pathname, nil)

    Pathname pointing to the Rails root, or nil.



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

.rootPathname

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.

Returns:

  • (Pathname)

    Pathname pointing to the project root.



15
16
17
# File 'lib/lokalise_rails/utils.rb', line 15

def root
  rails_root || Pathname.pwd
end