Sha256: 144b1fbd62766ea7773aa32d54ee95205a42e4933a79523a9a995483f53d9e5e

Contents?: true

Size: 878 Bytes

Versions: 3

Compression:

Stored size: 878 Bytes

Contents

require 'erb'
require 'pathname'
require 'hanami/environment'
require 'hanami/utils/string'

module Hanami
  # @api private
  class Welcome
    # @api private
    def initialize(_app)
      @root = Pathname.new(__dir__).join('templates').realpath
    end

    # @api private
    def call(env)
      @request_path = env['REQUEST_PATH'] || ''
      @body = [ERB.new(@root.join('welcome.html.erb').read).result(binding)]

      [200, {}, @body]
    end

    # @api private
    def application_name
      " #{ app }" if container?
    end

    private

    # @api private
    def container?
      Environment.new.container?
    end

    # @api private
    def application_class
      Hanami.configuration.apps do |app|
        return app if @request_path.include?(app.path_prefix)
      end
    end

    # @api private
    def app
      application_class.app_name
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-1.0.0 lib/hanami/welcome.rb
hanami-1.0.0.rc1 lib/hanami/welcome.rb
hanami-1.0.0.beta3 lib/hanami/welcome.rb