Sha256: 1e24efaf3acc0d42165fcb7c004077dfa65b7430ef70f48dcbaf07d884bef856

Contents?: true

Size: 1.34 KB

Versions: 10

Compression:

Stored size: 1.34 KB

Contents

module Flipper
  class Railtie < Rails::Railtie
    config.before_configuration do
      config.flipper = ActiveSupport::OrderedOptions.new.update(
        env_key: "flipper",
        memoize: true,
        preload: true,
        instrumenter: ActiveSupport::Notifications,
        log: true
      )
    end

    initializer "flipper.identifier" do
      ActiveSupport.on_load(:active_record) do
        ActiveRecord::Base.include Flipper::Identifier
      end
    end

    initializer "flipper.default", before: :load_config_initializers do |app|
      Flipper.configure do |config|
        config.default do
          Flipper.new(config.adapter, instrumenter: app.config.flipper.instrumenter)
        end
      end
    end

    initializer "flipper.log", after: :load_config_initializers do |app|
      flipper = app.config.flipper

      if flipper.log && flipper.instrumenter == ActiveSupport::Notifications
        require "flipper/instrumentation/log_subscriber"
      end
    end

    initializer "flipper.memoizer", after: :load_config_initializers do |app|
      flipper = app.config.flipper

      if flipper.memoize
        app.middleware.use Flipper::Middleware::Memoizer, {
          env_key: flipper.env_key,
          preload: flipper.preload,
          if: flipper.memoize.respond_to?(:call) ? flipper.memoize : nil
        }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flipper-0.26.0.rc2 lib/flipper/railtie.rb
flipper-0.26.0.rc1 lib/flipper/railtie.rb
flipper-0.25.4 lib/flipper/railtie.rb
flipper-0.25.3 lib/flipper/railtie.rb
flipper-0.25.2 lib/flipper/railtie.rb
flipper-0.25.1 lib/flipper/railtie.rb
flipper-0.25.0 lib/flipper/railtie.rb
flipper-0.24.1 lib/flipper/railtie.rb
flipper-0.24.0 lib/flipper/railtie.rb
flipper-0.23.1 lib/flipper/railtie.rb