Sha256: 75576ca51b0f69c1365dacba2f1eba33b7b807312a1a36b432bf513d247ef4d7

Contents?: true

Size: 935 Bytes

Versions: 2

Compression:

Stored size: 935 Bytes

Contents

require 'yaml'

module RapidRack
  class Engine < ::Rails::Engine
    isolate_namespace RapidRack

    configure do
      config.rapid_rack = OpenStruct.new
    end

    initializer 'rapid_rack.build_rack_application' do
      config.rapid_rack = OpenStruct.new(configuration)
      config.rapid_rack.authenticator = authenticator
    end

    def configuration
      return @configuration if @configuration

      file = Rails.root.join('config/rapidconnect.yml')
      fail("Missing configuration: #{file}") unless File.exist?(file)

      opts_from_file = YAML.load_file(file).symbolize_keys
      opts_from_app = config.rapid_rack.to_h

      @configuration = opts_from_file.merge(opts_from_app)
    end

    def authenticator
      return 'RapidRack::MockAuthenticator' if configuration[:development_mode]
      return 'RapidRack::TestAuthenticator' if configuration[:test_mode]
      'RapidRack::Authenticator'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rapid-rack-0.3.0 lib/rapid_rack/engine.rb
rapid-rack-0.2.0 lib/rapid_rack/engine.rb