delegating ControllerResource find to model adapter, uses 'get' for DataMapper - closes #373

This commit is contained in:
Ryan Bates
2011-05-21 13:57:17 -07:00
parent c031f82dd2
commit 613ab1c1ab
6 changed files with 29 additions and 1 deletions
+5 -1
View File
@@ -107,11 +107,15 @@ module CanCan
resource_base.send(@options[:find_by], id_param)
end
else
resource_base.find(id_param)
adapter.find(resource_base, id_param)
end
end
end
def adapter
ModelAdapters::AbstractAdapter.adapter_class(resource_class)
end
def authorization_action
parent? ? :show : @params[:action].to_sym
end
@@ -15,6 +15,11 @@ module CanCan
false # override in subclass
end
# Override if you need custom find behavior
def self.find(model_class, id)
model_class.find(id)
end
# Used to determine if this model adapter will override the matching behavior for a hash of conditions.
# If this returns true then matches_conditions_hash? will be called. See Rule#matches_conditions_hash
def self.override_conditions_hash_matching?(subject, conditions)
@@ -5,6 +5,10 @@ module CanCan
model_class <= DataMapper::Resource
end
def self.find(model_class, id)
model_class.get(id)
end
def self.override_conditions_hash_matching?(subject, conditions)
conditions.any? { |k,v| !k.kind_of?(Symbol) }
end