Sha256: 25c80f587ee4696897cac71b6de108a39a2a49f1835bd632e5af765a372f3ff2

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(/\A\/\z/, '')
      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-3.0.4 lib/alchemy/mount_point.rb
alchemy_cms-3.1.0.beta5 lib/alchemy/mount_point.rb
alchemy_cms-3.1.0.beta4 lib/alchemy/mount_point.rb
alchemy_cms-3.0.3 lib/alchemy/mount_point.rb
alchemy_cms-3.1.0.beta3 lib/alchemy/mount_point.rb
alchemy_cms-3.1.0.beta2 lib/alchemy/mount_point.rb
alchemy_cms-3.1.0.beta1 lib/alchemy/mount_point.rb
alchemy_cms-3.0.2 lib/alchemy/mount_point.rb
alchemy_cms-3.0.1 lib/alchemy/mount_point.rb
alchemy_cms-3.0.0 lib/alchemy/mount_point.rb
alchemy_cms-3.0.0.rc8 lib/alchemy/mount_point.rb
alchemy_cms-3.0.0.rc7 lib/alchemy/mount_point.rb
alchemy_cms-3.0.0.rc6 lib/alchemy/mount_point.rb
alchemy_cms-3.0.0.rc5 lib/alchemy/mount_point.rb