lib/ixtlan/guard/railtie.rb in ixtlan-guard-0.5.0 vs lib/ixtlan/guard/railtie.rb in ixtlan-guard-0.6.0

- old
+ new

@@ -1,25 +1,31 @@ require 'rails' -require 'ixtlan/guard' +require 'ixtlan/guard/guard_ng' +require 'ixtlan/guard/guard_rails' require 'logger' +require 'fileutils' module Ixtlan module Guard class Railtie < Rails::Railtie config.before_configuration do |app| - app.config.guard = - Ixtlan::Guard::Guard.new(:guard_dir => File.join(Rails.root, "app", "guards")) + app.config.guards_dir = File.join(Rails.root, "app", "guards") end config.after_initialize do |app| logger = app.config.logger || Rails.logger || Logger.new(STDERR) - app.config.guard.logger = logger unless defined?(Slf4r) - begin - app.config.guard.setup - rescue Ixtlan::Guard::GuardException => e - logger.warn e.message - end + 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) + app.config.guard = Ixtlan::Guard::GuardNG.new(options) + + ::ActionController::Base.send(:include, Ixtlan::ActionController::Guard) + ::ActionController::Base.send(:before_filter, :authorization) + ::ActionView::Base.send(:include, Ixtlan::Allowed) end config.generators do require 'rails/generators' require 'rails/generators/rails/controller/controller_generator'