Sha256: ab6bce5c6b2871934e292ff8511c8fb874dc5c2858070bd495ba80a1a8cf4267

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'rails'
require 'ixtlan/guard/guard'
require 'ixtlan/guard/guard_rails'
require 'logger'
require 'fileutils'

module Ixtlan
  module Guard
    class Railtie < Rails::Railtie

      config.before_configuration do |app|
        app.config.guards_dir = File.join(Rails.root, "app", "guards")
        # needs to be here ?!?
        ::ActionController::Base.send(:include, Ixtlan::Guard::ActionController)
        ::ActionView::Base.send(:include, Ixtlan::Guard::Allowed)
      end
      
      config.after_initialize do |app|
        logger = app.config.logger || Rails.logger || Logger.new(STDERR)
        options = {
          :guards_dir => app.config.guards_dir,
          :cache => app.config.cache_classes
        }
        options[:logger] = logger unless defined?(Slf4r)
        FileUtils.mkdir_p(app.config.guards_dir)

        controller = ::ApplicationController rescue ::ActionController::Base
        controller.send(:before_filter, :authorize)

        app.config.guard = Ixtlan::Guard::Guard.new(options)
      end
      
      config.generators do
        require 'rails/generators'
        require 'rails/generators/rails/controller/controller_generator'
        Rails::Generators::ControllerGenerator.hook_for :guard, :type => :boolean, :default => true do |controller|
          invoke controller, [ class_name, actions ]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ixtlan-guard-0.8.1 lib/ixtlan/guard/railtie.rb
ixtlan-guard-0.8.0 lib/ixtlan/guard/railtie.rb