Application path helpers

Configuring the root directory

The application root directory is defined as the directory containing the core application file.

You can see its definition in the core application file:

app.rb
Eucalypt.set_root __dir__

There shouldn't be a need to change this, but feel free if it is necessary for your application.

The set_root command also generates four helpers.

Root accessor

Eucalypt.root simply returns the full application root directory path as a string.

Path constructor

Eucalypt.path allows for the construction of absolute paths relative to the application root directory.

For example:

Eucalypt.path('spec', 'spec_helper.rb')
#=> /Users/eonu/ruby/web/apps/my-app/spec/spec_helper.rb

Glob helper

Eucalypt.glob allows for the globbing of files relative to the application root directory. The method works in the same way as Dir.glob, and also accepts a block that allows you to operate on the globbed files.

For example:

Eucalypt.glob('app', 'controllers', '*.rb') do |file|
    file_name = File.basename file, '.rb'
    controller_name = file_name.sub /_controller\Z/, ''
    puts controller_name
end

Require helper

Eucalypt.require allows for the requiring of multiple files relative to the application root directory. Note that it is not possible to specify the order in which files are required.

Unlike Kernel's require method, files must include their extensions.

For example:

# Bad - Raises error due to no extension on spec_helper.rb
Eucalypt.require 'spec', 'spec_helper'

# Good
Eucalypt.require 'spec', 'spec_helper.rb'
Eucalypt.require 'spec', 'support', '**', '*.rb'

Last updated