Sha256: bafb73c5815661c5dedf47f221d617a1cd67fbd074052bfff49827ba4726c238

Contents?: true

Size: 747 Bytes

Versions: 5

Compression:

Stored size: 747 Bytes

Contents

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

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

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

      [200, {}, @body]
    end

    def application_name
      " #{ app }" if container?
    end

    private

    def container?
      Environment.new.container?
    end

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

    def app
      application_class.app_name
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hanami-1.0.0.beta2 lib/hanami/welcome.rb
hanami-1.0.0.beta1 lib/hanami/welcome.rb
hanami-0.9.2 lib/hanami/welcome.rb
hanami-0.9.1 lib/hanami/welcome.rb
hanami-0.9.0 lib/hanami/welcome.rb