removing unused methods and a bit more refactoring
This commit is contained in:
parent
bbbc8a68e0
commit
5aa6252df6
|
@ -219,13 +219,5 @@ module CanCan
|
||||||
:update => [:edit],
|
:update => [:edit],
|
||||||
}
|
}
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ module CanCan
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_subject?(subject)
|
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
|
end
|
||||||
|
|
||||||
def can_without_base_behavior?(action, subject, extra_args)
|
def can_without_base_behavior?(action, subject, extra_args)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
module CanCan
|
module CanCan
|
||||||
|
# Used internally to load and authorize a given controller resource.
|
||||||
class ControllerResource # :nodoc:
|
class ControllerResource # :nodoc:
|
||||||
def initialize(controller, name, parent = nil, options = {})
|
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
|
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 @@ module CanCan
|
||||||
end
|
end
|
||||||
|
|
||||||
def model_class
|
def model_class
|
||||||
if @options[:resource].nil?
|
resource_class = @options[:resource]
|
||||||
|
if resource_class.nil?
|
||||||
@name.to_s.camelize.constantize
|
@name.to_s.camelize.constantize
|
||||||
elsif @options[:resource].kind_of? String
|
elsif resource_class.kind_of? String
|
||||||
@options[:resource].constantize
|
resource_class.constantize
|
||||||
else
|
else
|
||||||
@options[:resource]
|
resource_class # likely a symbol
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module CanCan
|
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:
|
class ResourceAuthorization # :nodoc:
|
||||||
attr_reader :params
|
|
||||||
|
|
||||||
def self.add_before_filter(controller_class, method, options = {})
|
def self.add_before_filter(controller_class, method, options = {})
|
||||||
controller_class.before_filter(options.slice(:only, :except)) do |controller|
|
controller_class.before_filter(options.slice(:only, :except)) do |controller|
|
||||||
ResourceAuthorization.new(controller, controller.params, options.except(:only, :except)).send(method)
|
ResourceAuthorization.new(controller, controller.params, options.except(:only, :except)).send(method)
|
||||||
|
@ -20,17 +20,17 @@ module CanCan
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_resource
|
def load_resource
|
||||||
unless collection_actions.include? params[:action].to_sym
|
unless collection_actions.include? @params[:action].to_sym
|
||||||
if new_actions.include? params[:action].to_sym
|
if new_actions.include? @params[:action].to_sym
|
||||||
resource.build(params[model_name.to_sym])
|
resource.build(@params[model_name.to_sym])
|
||||||
elsif params[:id]
|
elsif @params[:id]
|
||||||
resource.find(params[:id])
|
resource.find(@params[:id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize_resource
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -54,7 +54,7 @@ module CanCan
|
||||||
end
|
end
|
||||||
|
|
||||||
def model_name
|
def model_name
|
||||||
params[:controller].sub("Controller", "").underscore.split('/').last.singularize
|
@params[:controller].sub("Controller", "").underscore.split('/').last.singularize
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection_actions
|
def collection_actions
|
||||||
|
|
Loading…
Reference in New Issue
Block a user