Sha256: d961b696a72bb3dac491ee5bd7d7ab65f13a08314b888853488bb8c0541b10d3

Contents?: true

Size: 1.14 KB

Versions: 14

Compression:

Stored size: 1.14 KB

Contents

module Alchemy
  # Utitlities for Alchemy's mount point in the host rails app.
  #
  class MountPoint

    # 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 self.get(remove_leading_slash_if_blank = true)
      if self.mount_point == "/" && remove_leading_slash_if_blank
        self.mount_point.gsub(/^\/$/, '')
      else
        self.mount_point
      end
    end

    # Returns the routes object from Alchemy in the host app.
    #
    def self.routes
      ::Rails.application.routes.named_routes[:alchemy]
    end

    # Returns the raw mount point path from the Rails app routes.
    #
    # If Alchemy is not mounted in the main app, it falls back to root path.
    #
    def self.mount_point
      if self.routes.nil?
        ::Rails.logger.warn <<-WARN
Alchemy is not mounted! Falling back to root path (/).
If you want to change Alchemy's mount point, please mount Alchemy::Engine in your config/routes.rb file.
WARN
        return '/'
      end
      routes.path.spec.to_s
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
alchemy_cms-2.9.1 lib/alchemy/mount_point.rb
alchemy_cms-2.9.0 lib/alchemy/mount_point.rb
alchemy_cms-2.8.3 lib/alchemy/mount_point.rb
alchemy_cms-2.7.5 lib/alchemy/mount_point.rb
alchemy_cms-2.6.3 lib/alchemy/mount_point.rb
alchemy_cms-2.7.4 lib/alchemy/mount_point.rb
alchemy_cms-2.8.2 lib/alchemy/mount_point.rb
alchemy_cms-2.8.1 lib/alchemy/mount_point.rb
alchemy_cms-2.7.3 lib/alchemy/mount_point.rb
alchemy_cms-2.7.2 lib/alchemy/mount_point.rb
alchemy_cms-2.7.1 lib/alchemy/mount_point.rb
alchemy_cms-2.7.0 lib/alchemy/mount_point.rb
alchemy_cms-2.6.2.1 lib/alchemy/mount_point.rb
alchemy_cms-2.6.2 lib/alchemy/mount_point.rb