<commit_before>module Flipflop
  class Engine < ::Rails::Engine
    isolate_namespace Flipflop

    config.app_middleware.insert_after ActionDispatch::Callbacks,
      FeatureCache::Middleware

    config.flipflop = ActiveSupport::OrderedOptions.new

    initializer "flipflop.assets" do |app|
      config.assets.precompile += ["flipflop.css"]
    end

    initializer "flipflop.features_path" do |app|
      app.paths.add("config/features.rb")
    end

    initializer "flipflop.features_reloader" do |app|
      app.reloaders.push(reloader = feature_reloader(app))
      to_prepare do
        reloader.execute
      end
    end

    initializer "flipflop.dashboard", after: "flipflop.features_reloader" do |app|
      if action = config.flipflop.dashboard_access_filter
        to_prepare do
          Flipflop::FeaturesController.before_action(action)
          Flipflop::StrategiesController.before_action(action)
        end
      else
        warn("WARNING: You have not set `config.flipflop.dashboard_access_filter`; " +
             "the Flipflop dashboard is now always public!")
      end
    end

    initializer "flipflop.request_interceptor" do |app|
      interceptor = Strategies::AbstractStrategy::RequestInterceptor
      ActionController::Base.send(:include, interceptor)
    end

    private

    def feature_reloader(app)
      features = app.paths["config/features.rb"].existent
      ActiveSupport::FileUpdateChecker.new(features) do
        features.each { |path| load(path) }
      end
    end

    def to_prepare
      klass = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader
      klass.to_prepare(&Proc.new)
    end
  end
end
<commit_msg>Engine improvements.<commit_after>module Flipflop
  class Engine < ::Rails::Engine
    isolate_namespace Flipflop

    config.app_middleware.insert_after ActionDispatch::Callbacks,
      FeatureCache::Middleware

    config.flipflop = ActiveSupport::OrderedOptions.new

    initializer "flipflop.assets" do |app|
      config.assets.precompile += ["flipflop.css"]
    end

    initializer "flipflop.features_path" do |app|
      app.paths.add("config/features.rb")
    end

    initializer "flipflop.features_reloader" do |app|
      app.reloaders.push(reloader = feature_reloader(app))
      to_prepare do
        reloader.execute
      end
    end

    initializer "flipflop.dashboard", after: "flipflop.features_reloader" do |app|
      if actions = config.flipflop.dashboard_access_filter
        to_prepare do
          Flipflop::FeaturesController.before_action(*actions)
          Flipflop::StrategiesController.before_action(*actions)
        end
      else
        unless defined?(Rails::Generators) or defined?(Rake)
          warn("WARNING: You have not set `config.flipflop.dashboard_access_filter`; " +
               "the Flipflop dashboard is now always public!")
        end
      end
    end

    initializer "flipflop.request_interceptor" do |app|
      interceptor = Strategies::AbstractStrategy::RequestInterceptor
      ActionController::Base.send(:include, interceptor)
    end

    private

    def feature_reloader(app)
      features = app.paths["config/features.rb"].existent
      ActiveSupport::FileUpdateChecker.new(features) do
        features.each { |path| load(path) }
      end
    end

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

{'fraction_non_alphanumeric': 0.09122104661138118, 'fraction_numerical': 0.0, 'mean_word_length': 3.2144578313253014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7423743', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1033, 'n_words': 200}