Module: LokaliseRails::Utils

Defined in:
lib/lokalise_rails/utils.rb

Overview

Utility methods for LokaliseRails

Class Method Summary collapse

Class Method Details

.rails_rootString?

Determines the root directory of a Rails project.

  • Uses ‘Rails.root` if available.

  • Falls back to ‘RAILS_ROOT` for older Rails versions.

  • Returns ‘nil` if Rails is not present.

Returns:

  • (String, nil)

    Path to the root directory or ‘nil` if not found.



26
27
28
29
30
31
# File 'lib/lokalise_rails/utils.rb', line 26

def rails_root
  return ::Rails.root.to_s if defined?(::Rails.root) && ::Rails.root
  return RAILS_ROOT.to_s if defined?(RAILS_ROOT)

  nil
end

.rootPathname

Retrieves the root directory of the current project.

If Rails is available, it returns ‘Rails.root`. Otherwise, it defaults to the current working directory.

Returns:

  • (Pathname)

    Pathname object pointing to the project root.



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

def root
  Pathname.new(rails_root || Dir.getwd)
end