Module: Hanami::App::ClassMethods

Defined in:
lib/hanami/app.rb

Overview

App class interface

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configHanami::Config (readonly)

Returns the app’s config.

Returns:

Since:

  • 2.0.0



45
46
47
# File 'lib/hanami/app.rb', line 45

def config
  @config
end

Instance Method Details

#app_nameHanami::SliceName

Returns the app’s SliceName.

Returns:

See Also:

Since:

  • 2.0.0



55
56
57
# File 'lib/hanami/app.rb', line 55

def app_name
  slice_name
end

#prepare_load_pathself

Prepares the $LOAD_PATH based on the app’s configured root, prepending the ‘lib/` directory if it exists. If the lib directory is already added, this will do nothing.

In ordinary circumstances, you should never have to call this method: this method is called immediately upon subclassing Hanami::App, as a convenicence to put lib/ (under the default root of ‘Dir.pwd`) on the load path automatically. This is helpful if you need to require files inside the subclass body for performing certain app configuration steps.

If you change your app’s ‘config.root` and you need to require files from its `lib/` directory within your Hanami::App subclass body, you should call #prepare_load_path explicitly after setting the new root.

Otherwise, this method is called again as part of the app prepare step, so if you’ve changed your app’s root and do not need to require files within your Hanami::App subclass body, then you don’t need to call this method.

Examples:

module MyApp
  class App < Hanami::App
    config.root = Pathname(__dir__).join("../src")
    prepare_load_path

    # You can make requires for your files here
  end
end

Returns:

  • (self)

Since:

  • 2.0.0



89
90
91
92
93
94
95
96
# File 'lib/hanami/app.rb', line 89

def prepare_load_path
  if (lib_path = root.join(LIB_DIR)).directory?
    path = lib_path.realpath.to_s
    $LOAD_PATH.prepend(path) unless $LOAD_PATH.include?(path)
  end

  self
end