Module: Hanami::App::ClassMethods
- Defined in:
- lib/hanami/app.rb
Overview
App class interface
Instance Attribute Summary collapse
-
#config ⇒ Hanami::Config
readonly
Returns the app’s config.
Instance Method Summary collapse
-
#app_name ⇒ Hanami::SliceName
Returns the app’s SliceName.
-
#prepare_load_path ⇒ self
Prepares the $LOAD_PATH based on the app’s configured root, prepending the ‘lib/` directory if it exists.
Instance Attribute Details
#config ⇒ Hanami::Config (readonly)
Returns the app’s config.
45 46 47 |
# File 'lib/hanami/app.rb', line 45 def config @config end |
Instance Method Details
#app_name ⇒ Hanami::SliceName
Returns the app’s SliceName.
55 56 57 |
# File 'lib/hanami/app.rb', line 55 def app_name slice_name end |
#prepare_load_path ⇒ self
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.
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 |