lib/access-granted/permission.rb in access-granted-1.1.2 vs lib/access-granted/permission.rb in access-granted-1.2.0
- old
+ new
@@ -1,15 +1,16 @@
module AccessGranted
class Permission
- attr_reader :action, :subject, :granted, :conditions, :block
+ attr_reader :action, :subject, :granted, :conditions, :actions, :block
- def initialize(granted, action, subject, user = nil, conditions = {}, block = nil)
+ def initialize(granted, action, subject, user = nil, conditions = {}, actions = [], block = nil)
@action = action
@user = user
@granted = granted
@subject = subject
@conditions = conditions
+ @actions = actions
@block = block
end
def matches_action?(action)
@action == action
@@ -18,13 +19,15 @@
def matches_subject?(subject)
subject == @subject || subject.class <= @subject
end
def matches_conditions?(subject)
- if @block && !subject.is_a?(Class)
+ if @block
@block.call(subject, @user)
- else
+ elsif !@conditions.empty?
matches_hash_conditions?(subject)
+ else
+ true
end
end
def matches_hash_conditions?(subject)
@conditions.each_pair do |name, value|