Sha256: a91272fcbe07c2c6a98abcf0f640fae7127ae1d22ef6a3be95330d5bbbb36ecd

Contents?: true

Size: 1.6 KB

Versions: 15

Compression:

Stored size: 1.6 KB

Contents

module Challah
  class Engine < ::Rails::Engine

    initializer 'challah.router' do |app|
      app.routes_reloader.paths.insert(0, File.expand_path(File.join(File.dirname(__FILE__), 'routes.rb')))
    end

    initializer 'challah.active_record' do
      ActiveSupport.on_load :active_record do
        Challah::Engine.setup_active_record!
      end
    end

    initializer 'challah.action_controller' do
      ActiveSupport.on_load :action_controller do
        Challah::Engine.setup_action_controller!
      end
    end

    # Set up controller methods
    def self.setup_action_controller!
      if defined?(ActionController)
        ActionController::Base.send(:include, Challah::Controller)
        ActionController::Base.send(:helper_method,
          :current_user_session,
          :current_user,
          :current_user?,
          :logged_in?,
          :signed_in?
        )

        # Load any ActionController/Challah plugins
        Challah.plugins.values.each do |plugin|
          plugin.action_controller.each do |proc|
            proc.call
          end
        end
      end
    end

    # Set up active record with Challah methods
    def self.setup_active_record!
      if defined?(ActiveRecord)
        Challah.options[:logger] = ActiveRecord::Base.logger

        ActiveRecord::Base.send(:include, Challah::ActiveRecordExtensions)
        ActiveRecord::Base.send(:include, Challah::Audit)

        # Load any ActiveRecord/Challah plugins
        Challah.plugins.values.each do |plugin|
          plugin.active_record.each do |proc|
            proc.call
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
challah-1.3.3 lib/challah/engine.rb
challah-1.3.2 lib/challah/engine.rb
challah-1.3.1 lib/challah/engine.rb
challah-1.3.0 lib/challah/engine.rb
challah-1.2.11 lib/challah/engine.rb
challah-1.2.10 lib/challah/engine.rb
challah-1.2.9 lib/challah/engine.rb
challah-1.2.8 lib/challah/engine.rb
challah-1.2.7 lib/challah/engine.rb
challah-1.2.6 lib/challah/engine.rb
challah-1.2.5 lib/challah/engine.rb
challah-1.2.5.pre lib/challah/engine.rb
challah-1.2.4 lib/challah/engine.rb
challah-1.2.3 lib/challah/engine.rb
challah-1.2.2 lib/challah/engine.rb