Sha256: 18328492de6def203e4f33498e57746f3e9556374ea38bd5ef092d777df860bc

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require 'skylight'
require 'rails'

module Skylight
  class Railtie < Rails::Railtie
    config.skylight = ActiveSupport::OrderedOptions.new

    # The environments in which skylight should be inabled
    config.skylight.environments = ['production']

    # The path to the configuration file
    config.skylight.config_path = "config/skylight.yml"

    attr_accessor :instrumenter

    initializer "skylight.sanity_check" do |app|
      checker = SanityChecker.new
      @problems = checker.smoke_test(config_path(app)) || checker.sanity_check(load_config(app))
      next unless @problems

      @problems.each do |group, problem_list|
        problem_list.each do |problem|
          puts "[SKYLIGHT] PROBLEM: #{group} #{problem}"
        end
      end
    end

    initializer "skylight.configure" do |app|
      if @problems
        puts "[SKYLIGHT] Skipping Skylight boot"
      else
        Rails.logger.debug "[SKYLIGHT] Installing middleware"
        app.middleware.insert 0, Middleware, load_config(app)
      end
    end

  private

    def environments
      Array(config.skylight.environments).map { |e| e && e.to_s }.compact
    end

    def config_path(app)
      path = config.skylight.config_path
      File.expand_path(path, app.root)
    end

    def load_config(app)
      @skylight_config ||= begin
        config = Config.load_from_yaml(config_path(app), ENV).tap do |c|
          c.logger = Rails.logger
        end

        config.normalizer.view_paths = app.config.paths["app/views"].existent
        config.http = Util::HTTP.new(config)
        config
      end
    rescue => e
      raise
      Rails.logger.error "[SKYLIGHT] #{e.message} (#{e.class}) - #{e.backtrace.first}"
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skylight-0.0.10 lib/skylight/railtie.rb