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.



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

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.



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

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