Sha256: c24b951c8a755e8627b22055b6ebca9e256fd314b7fd49f773b6f3c38d3d741b

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

module Chanko
  class Railtie < Rails::Railtie
    initializer "chanko" do |app|
      ActiveSupport.on_load :action_view do
        ::ActionView::Base.send(:include, Helper, Invoker, UnitProxyProvider)
      end
      ActiveSupport.on_load :action_controller do
        ::ActionController::Base.send(:include, Controller, Invoker, UnitProxyProvider)
      end
      ActiveSupport.on_load :active_record do
        ::ActiveRecord::Base.send(:include, UnitProxyProvider)
        ::ActiveRecord::Relation.send(:include, UnitProxyProvider)
        ::ActiveRecord::Associations::CollectionAssociation.send(:include, UnitProxyProvider)
      end
    end

    initializer("chanko.support_zeitwerk") do |app|
      if Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled?
        Rails.autoloaders.main.collapse(Rails.root.join(Chanko::Config.units_directory_path, '*'))
      end
    end

    initializer("chanko.prevent_units_directory_from_eager_loading", before: :set_autoload_paths) do |app|
      if Chanko::Config.eager_load
        Rails.configuration.eager_load_paths.delete(Rails.root.join(Chanko::Config.units_directory_path).to_s)
      end
    end

    initializer("chanko.eager_load_units") do |app|
      if Chanko::Config.eager_load
        Chanko::Loader.eager_load_units!
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chanko-2.2.1 lib/chanko/railtie.rb
chanko-2.2.0 lib/chanko/railtie.rb