Sha256: 9b931cf0d5a4f654f5cf7a842d5021c00a7cd14bd48847c3b853420451406692

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

require 'sinatra'
require 'haml'

require 'hcheck'
require 'hcheck/application/helpers/responders'

module Hcheck
  # base sinatra application
  class SinatraBase < Sinatra::Base
    set :public_dir, File.expand_path('application/assets', __dir__)
    set :views, File.expand_path('application/views', __dir__)
    set :haml, format: :html5

    include Hcheck::ApplicationHelpers::Responders
  end

  # sinatra that gets booted when run in standalone mode
  class Application < SinatraBase
    get('/hcheck') { h_status }
  end

  # sinatra when mounted to rails
  class Status < SinatraBase
    def initialize(app = nil)
      Hcheck::Configuration.load_default
    rescue Hcheck::Errors::ConfigurationError => e
      @config_error = e
    ensure
      super(app)
    end

    get('/') do
      if @config_error
        Hcheck.logger.error @config_error.message

        respond_with Hcheck::Errors::ConfigurationError::MSG, 500, :error
      else
        h_status
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hcheck-0.1.1 lib/hcheck/application.rb
hcheck-0.1.0 lib/hcheck/application.rb