lib/access-granted/role.rb in access-granted-0.0.2 vs lib/access-granted/role.rb in access-granted-0.1.0
- old
+ new
@@ -26,25 +26,20 @@
def cannot(action, subject, conditions = {}, &block)
add_permission(false, action, subject, conditions, block)
end
- def can?(action, subject)
- permission = find_permission(action, subject)
- permission ? permission.granted : false
- end
-
def find_permission(action, subject)
relevant_permissions(action, subject).detect do |permission|
permission.matches_conditions?(subject)
end
end
def applies_to?(user)
case @conditions
when Hash
- matches_hash(user, @conditions)
+ matches_hash?(user, @conditions)
when Proc
@conditions.call(user)
else
true
end
@@ -55,11 +50,11 @@
permissions_by_action(action).select do |perm|
perm.matches_subject?(subject)
end
end
- def matches_hash(user, conditions = {})
+ def matches_hash?(user, conditions = {})
conditions.all? do |name, value|
user.send(name) == value
end
end
@@ -74,10 +69,10 @@
private
def prepare_actions(action)
if action == :manage
- actions = [:create, :update, :destroy]
+ actions = [:read, :create, :update, :destroy]
else
actions = [action].flatten
end
end