Sha256: effdfc68a0278c7c711d32140314b46c14fa3394c8ca3b6cb5445e7bb609024a

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Sail
  # Engine
  # Defines initializers and
  # after initialize hooks
  class Engine < ::Rails::Engine
    require "jquery-rails" if Rails::VERSION::MAJOR < 5
    isolate_namespace Sail

    config.generators do |g|
      g.test_framework :rspec
    end

    initializer "sail.assets.precompile" do |app|
      app.config.assets.precompile += %w[sail/refresh.svg sail/sort.svg sail/angle-left.svg
                                         sail/angle-right.svg sail/link.svg sail/cog.svg]
    end

    initializer "sail" do
      unless Sail.configuration.dashboard_auth_lambda.nil?
        to_prepare do
          Sail::SettingsController.before_action(*Sail.configuration.dashboard_auth_lambda)
        end
      end
    end

    config.after_initialize do
      errors = [ActiveRecord::NoDatabaseError]
      errors << PG::ConnectionBad if defined?(PG)

      begin
        Sail::Setting.load_defaults unless Rails.env.test?
      rescue *errors
        warn "Skipping setting creation because database doesn't exist"
      end
    end

    private

    def to_prepare
      klass = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader
      klass.to_prepare(&Proc.new)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sail-3.0.1 lib/sail/engine.rb
sail-3.0.0 lib/sail/engine.rb