Class: Alchemy::MountPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy/mount_point.rb

Overview

Utilities for Alchemy’s mount point in the host rails app.

Constant Summary collapse

MOUNT_POINT_REGEXP =
/mount\sAlchemy::Engine\s=>\s['|"](\/\w*)['|"]/

Class Method Summary collapse

Class Method Details

.get(remove_leading_slash_if_blank = true) ⇒ Object

Returns the path of Alchemy’s mount point in current rails app.

Parameters:

  • remove_leading_slash_if_blank (Boolean) (defaults to: true)

    Pass false to not return a leading slash on empty mount point.



17
18
19
20
21
22
23
# File 'lib/alchemy/mount_point.rb', line 17

def get(remove_leading_slash_if_blank = true)
  if path == "/" && remove_leading_slash_if_blank
    path.gsub(/\A\/\z/, '')
  else
    path
  end
end

.pathObject

Returns the mount point path from the Rails app routes.



27
28
29
30
31
32
33
34
# File 'lib/alchemy/mount_point.rb', line 27

def path
  match = File.read(routes_file_path).match(MOUNT_POINT_REGEXP)
  if match.nil?
    raise NotMountedError
  else
    match[1]
  end
end