Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removing unused methods and a bit more refactoring

  • Loading branch information...
commit 5aa6252df66eab7e96ba1240b432fcb068a68386 1 parent bbbc8a6
Ryan Bates authored
8 lib/cancan/ability.rb
View
@@ -219,13 +219,5 @@ def default_alias_actions
:update => [:edit],
}
end
-
- def includes_action?(actions, action)
- actions.include?(:manage) || actions.include?(action)
- end
-
- def includes_subject?(subjects, subject)
- subjects.include?(:all) || subjects.include?(subject) || subjects.any? { |c| c.kind_of?(Class) && subject.kind_of?(c) }
- end
end
end
2  lib/cancan/can_definition.rb
View
@@ -33,7 +33,7 @@ def matches_action?(action)
end
def matches_subject?(subject)
- @subjects.include?(:all) || @subjects.include?(subject) || @subjects.any? { |c| c.kind_of?(Class) && subject.kind_of?(c) }
+ @subjects.include?(:all) || @subjects.include?(subject) || @subjects.any? { |sub| sub.kind_of?(Class) && subject.kind_of?(sub) }
end
def can_without_base_behavior?(action, subject, extra_args)
10 lib/cancan/controller_resource.rb
View
@@ -1,4 +1,5 @@
module CanCan
+ # Used internally to load and authorize a given controller resource.
class ControllerResource # :nodoc:
def initialize(controller, name, parent = nil, options = {})
raise ImplementationRemoved, "The :class option has been renamed to :resource for specifying the class in CanCan." if options.has_key? :class
@@ -9,12 +10,13 @@ def initialize(controller, name, parent = nil, options = {})
end
def model_class
- if @options[:resource].nil?
+ resource_class = @options[:resource]
+ if resource_class.nil?
@name.to_s.camelize.constantize
- elsif @options[:resource].kind_of? String
- @options[:resource].constantize
+ elsif resource_class.kind_of? String
+ resource_class.constantize
else
- @options[:resource]
+ resource_class # likely a symbol
end
end
18 lib/cancan/resource_authorization.rb
View
@@ -1,7 +1,7 @@
module CanCan
+ # Handle the load and authorization controller logic so we don't clutter up all controllers with non-interface methods.
+ # This class is used internally, so you do not need to call methods directly on it.
class ResourceAuthorization # :nodoc:
- attr_reader :params
-
def self.add_before_filter(controller_class, method, options = {})
controller_class.before_filter(options.slice(:only, :except)) do |controller|
ResourceAuthorization.new(controller, controller.params, options.except(:only, :except)).send(method)
@@ -20,17 +20,17 @@ def load_and_authorize_resource
end
def load_resource
- unless collection_actions.include? params[:action].to_sym
- if new_actions.include? params[:action].to_sym
- resource.build(params[model_name.to_sym])
- elsif params[:id]
- resource.find(params[:id])
+ unless collection_actions.include? @params[:action].to_sym
+ if new_actions.include? @params[:action].to_sym
+ resource.build(@params[model_name.to_sym])
+ elsif @params[:id]
+ resource.find(@params[:id])
end
end
end
def authorize_resource
- @controller.authorize!(params[:action].to_sym, resource.model_instance || resource.model_class)
+ @controller.authorize!(@params[:action].to_sym, resource.model_instance || resource.model_class)
end
private
@@ -54,7 +54,7 @@ def parent_resource
end
def model_name
- params[:controller].sub("Controller", "").underscore.split('/').last.singularize
+ @params[:controller].sub("Controller", "").underscore.split('/').last.singularize
end
def collection_actions
Please sign in to comment.
Something went wrong with that request. Please try again.