Sha256: 855f666bb59e3ba277af574aad8043e8550e74f9f8ac4234b1b32e528e8adb6d

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

require 'chillout/creation_listener'
require 'chillout/listener_injector'

module Chillout
  class Railtie < Rails::Railtie
    config.chillout = ActiveSupport::OrderedOptions.new
    initializer "chillout.creations_listener_initialization" do |rails_app|
      chillout_config = rails_app.config.chillout
      if chillout_config.present?
        RailsInitializer.new(rails_app, chillout_config, Rails.logger).start
      else
        Rails.logger.debug "[Chillout] Not enabled for #{Rails.env}"
      end
    end

    rake_tasks do
      load "chillout/tasks.rb"
    end

    generators do
      require "chillout/generators/install"
    end
  end

  class RailsInitializer

    def initialize(rails_app, chillout_config, rails_logger)
      @rails_app = rails_app
      @chillout_config = chillout_config
      @rails_logger = rails_logger
    end

    def start(listeners_injector = ListenerInjector.new)
      listeners_injector.logger = @rails_logger

      @rails_logger.info "[Chillout] Railtie initializing"
      client = Client.new(@chillout_config[:secret], options)
      listeners_injector.inject!
      @rails_app.middleware.use Middleware::CreationsMonitor, client
      @rails_logger.info "[Chillout] Creation monitor enabled"
      sidekiq = Integrations::Sidekiq.new
      sidekiq.enable(client) if sidekiq.available?
      client.start
    end

    def options
      {logger: @rails_logger}.merge(@chillout_config).except(:secret)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chillout-0.8.2 lib/chillout/railtie.rb
chillout-0.8.1 lib/chillout/railtie.rb
chillout-0.8.0 lib/chillout/railtie.rb