class AccessGranted::Permission
Attributes
action[R]
actions[R]
block[R]
conditions[R]
granted[R]
subject[R]
Public Class Methods
new(granted, action, subject, user = nil, conditions = {}, actions = [], block = nil)
click to toggle source
# File lib/access-granted/permission.rb, line 5 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
Public Instance Methods
==(other)
click to toggle source
# File lib/access-granted/permission.rb, line 47 def ==(other) eql?(other) end
eql?(other)
click to toggle source
# File lib/access-granted/permission.rb, line 40 def eql?(other) other.class == self.class && @action == other.action && @subject == other.subject && @granted == other.granted end
matches_action?(action)
click to toggle source
# File lib/access-granted/permission.rb, line 15 def matches_action?(action) @action == action end
matches_conditions?(subject)
click to toggle source
# File lib/access-granted/permission.rb, line 23 def matches_conditions?(subject) if @block @block.call(subject, @user) elsif !@conditions.empty? matches_hash_conditions?(subject) else true end end
matches_hash_conditions?(subject)
click to toggle source
# File lib/access-granted/permission.rb, line 33 def matches_hash_conditions?(subject) @conditions.each_pair do |name, value| return false if subject.send(name) != value end true end
matches_subject?(subject)
click to toggle source
# File lib/access-granted/permission.rb, line 19 def matches_subject?(subject) subject == @subject || subject.class <= @subject end