Sha256: 5ff6088ca1f67929657982d009b37c8b5e7550c11f694bd64d7d64908640e0a8

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

require 'rails'

module Alchemy
  # Utilities for Alchemy's mount point in the host rails app.
  #
  class MountPoint
    MOUNT_POINT_REGEXP = /mount\sAlchemy::Engine\s=>\s['|"](\/\w*)['|"]/

    class << self
      # Returns the path of Alchemy's mount point in current rails app.
      #
      # @param [Boolean] remove_leading_slash_if_blank
      #   Pass false to not return a leading slash on empty mount point.
      #
      def get(remove_leading_slash_if_blank = true)
        if path == "/" && remove_leading_slash_if_blank
          path.gsub(/\A\/\z/, '')
        else
          path
        end
      end

      # Returns the mount point path from the Rails app routes.
      #
      def path
        match = File.read(routes_file_path).match(MOUNT_POINT_REGEXP)
        if match.nil?
          raise NotMountedError
        else
          match[1]
        end
      end

      private

      def routes_file_path
        if Rails.root
          Rails.root.join('config/routes.rb')
        else
          'config/routes.rb'
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
alchemy_cms-3.4.2 lib/alchemy/mount_point.rb
alchemy_cms-3.5.0.rc1 lib/alchemy/mount_point.rb
alchemy_cms-3.4.1 lib/alchemy/mount_point.rb
alchemy_cms-3.3.3 lib/alchemy/mount_point.rb
alchemy_cms-3.3.2 lib/alchemy/mount_point.rb
alchemy_cms-3.4.0 lib/alchemy/mount_point.rb
alchemy_cms-3.4.0.rc1 lib/alchemy/mount_point.rb
alchemy_cms-3.3.1 lib/alchemy/mount_point.rb
alchemy_cms-3.3.0 lib/alchemy/mount_point.rb
alchemy_cms-3.3.0.rc2 lib/alchemy/mount_point.rb
alchemy_cms-3.3.0.rc1 lib/alchemy/mount_point.rb