# frozen_string_literal: true
require 'rails'

module Mnemosyne
  class Railtie < ::Rails::Railtie
    initializer 'mnemosyne.initialize' do |app|
      config = app.config_for('mnemosyne')

      config['application'] ||= app.class.name.underscore.titleize

      config['logger']  ||= Rails.logger
      config['enabled'] ||= config.key?('server')

      config = ::Mnemosyne::Config.new(config)

      if config.enabled?
        ::Mnemosyne::Instrumenter.start!(config)

        app.middleware.insert 0, ::Mnemosyne::Middleware::Rack
      else
        config.logger.warn '[MNEMOSYNE] Instrumenter not enabled.'
      end
    end
  end
end

# frozen_string_literal: true
require 'rails'

module Mnemosyne
  class Railtie < ::Rails::Railtie
    initializer 'mnemosyne.initialize' do |app|
      config = app.config_for('mnemosyne')

      config['application'] ||= app.class.name.underscore.titleize

      config['logger'] ||= Rails.logger

      # If a server URL is configured, we assume that Mnemosyne should be enabled
      config['enabled'] = config.key?('server') unless config.key?('enabled')

      config = ::Mnemosyne::Config.new(config)

      if config.enabled?
        ::Mnemosyne::Instrumenter.start!(config)

        app.middleware.insert 0, ::Mnemosyne::Middleware::Rack
      else
        config.logger.warn '[MNEMOSYNE] Instrumenter not enabled.'
      end
    end
  end
end

Fix falsy "enabled" flag being ignored
Fix falsy "enabled" flag being ignored

Because of using the `||=` operator, falsy values for `enabled` were
being ignored and overwritten when the `server` flag existed.

For mnemosyne.yml files like the following:

    common: &common
      server: amqp://localhost

    development:
      <<: *common
      enabled: false

...this meant that the `enabled: false` was being ignored for the
development environment.