lib/fume/cancan/controller_extensions.rb in fume-cancan-0.0.3 vs lib/fume/cancan/controller_extensions.rb in fume-cancan-0.0.4
- old
+ new
@@ -2,33 +2,30 @@
module Fume
module Cancan
module ControllerExtensions
extend ActiveSupport::Concern
-
+
module ClassMethods
- def authorize_object(options = {})
- filter_options = options.slice(:only, :except) if options.is_a?(Hash)
+ def authorize_object(*args)
+ options = args.extract_options!
+ object = args.shift || options[:object]
+
+ filter_options = options.slice(:only, :except)
before_filter(filter_options || {}) do |controller|
- controller.send :authorize_object!, options
+ controller.send :authorize_object!, object, options
end
end
end
-
+
protected
- def authorize_object!(options)
- action = params[:action].to_sym
- case options
- when Hash
- authorize! action, options[:object]
- else
- authorize! action, options
- end
+ def authorize_object!(object, options = {})
+ action = (options[:action] || params[:action]).to_sym
+ authorize! action, object
end
-
end
end
end
if defined? ActionController::Base
ActionController::Base.send :include, ::Fume::Cancan::ControllerExtensions
-end
\ No newline at end of file
+end