Method: Hanami.app_path

Defined in:
lib/hanami.rb

.app_path(dir = Dir.pwd) ⇒ Pathname?

Finds and returns the absolute path for the Hanami app file (config/app.rb).

Searches within the given directory, then searches upwards through parent directories until the app file can be found.

Parameters:

  • dir (String, Pathname) (defaults to: Dir.pwd)

    The directory from which to start searching. Defaults to the current directory.

Returns:

  • (Pathname, nil)

    the app file path, or nil if not found.

Since:

  • 2.0.0



144
145
146
147
148
149
150
151
152
153
# File 'lib/hanami.rb', line 144

def self.app_path(dir = Dir.pwd)
  dir = Pathname(dir).expand_path
  path = dir.join(APP_PATH)

  if path.file?
    path
  elsif !dir.root?
    app_path(dir.parent)
  end
end