Sha256: 9eddb0f00f5631cf0a361b358fab63aaf2b8193989ff850d330c719fc8bb5500

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 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.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.memoizer" do |app|
      config = app.config.flipper

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

    initializer "flipper.log" do |app|
      config = app.config.flipper
      if config.log && config.instrumenter == ActiveSupport::Notifications
        require "flipper/instrumentation/log_subscriber"
      end
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flipper-0.23.0 lib/flipper/railtie.rb
flipper-0.22.2 lib/flipper/railtie.rb