Sha256: 4a87249e4bde45c4ee34203328206351d85606aa80752793037933ec46870a4e

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

module Challah
  require 'abstract_controller/rendering'

  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 |app|
      ActiveSupport.on_load :active_record do
        Challah::Engine.setup_active_record!
      end
    end

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

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

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

          ActiveRecord::Base.send(:extend, Challah::AuthablePermission)
          ActiveRecord::Base.send(:extend, Challah::AuthablePermissionRole)
          ActiveRecord::Base.send(:extend, Challah::AuthablePermissionUser)
          ActiveRecord::Base.send(:extend, Challah::AuthableRole)
          ActiveRecord::Base.send(:extend, Challah::AuthableUser)
          ActiveRecord::Base.send(:include, Challah::Audit)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
challah-0.6.2 lib/challah/railtie.rb
challah-0.6.1 lib/challah/railtie.rb