@@ -6,28 +6,29 @@ module LokaliseRails
66 # Utility methods for LokaliseRails
77 module Utils
88 class << self
9- # Retrieves the root directory of the current project.
9+ # Returns the root directory of the current project.
1010 #
11- # If Rails is available, it returns `Rails.root`. Otherwise, it defaults
12- # to the current working directory.
11+ # If Rails is available, this returns `Rails.root`.
12+ # Otherwise, it falls back to the current working directory.
1313 #
14- # @return [Pathname] Pathname object pointing to the project root.
14+ # @return [Pathname] Pathname pointing to the project root.
1515 def root
16- Pathname . new ( rails_root || Dir . getwd )
16+ rails_root || Pathname . pwd
1717 end
1818
19- # Determines the root directory of a Rails project .
19+ # Returns the root directory of a Rails application, if present .
2020 #
21- # - Uses `Rails.root` if available .
22- # - Falls back to `RAILS_ROOT` for older Rails versions.
23- # - Returns `nil` if Rails is not present .
21+ # - Uses `Rails.root` when Rails is loaded .
22+ # - Falls back to `RAILS_ROOT` for legacy Rails versions.
23+ # - Returns `nil` when Rails is not available .
2424 #
25- # @return [String , nil] Path to the root directory or `nil` if not found .
25+ # @return [Pathname , nil] Pathname pointing to the Rails root, or `nil`.
2626 def rails_root
27- return ::Rails . root . to_s if defined? ( ::Rails . root ) && ::Rails . root
28- return RAILS_ROOT . to_s if defined? ( RAILS_ROOT )
29-
30- nil
27+ if defined? ( ::Rails ) && ::Rails . respond_to? ( :root ) && ::Rails . root
28+ Pathname ( ::Rails . root )
29+ elsif defined? ( ::RAILS_ROOT )
30+ Pathname ( ::RAILS_ROOT )
31+ end
3132 end
3233 end
3334 end
0 commit comments