Sha256: 54109c98a3bc0911cd44674c223cb0c0937f9157bbc891c2b5eacd5c54c3e249
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
module AccessGranted class Permission attr_reader :action, :subject, :granted, :conditions def initialize(granted, action, subject, conditions = {}, block = nil) @action = action @granted = granted @subject = subject @conditions = conditions @block = block end def matches_action?(action) @action == action end def matches_subject?(subject) subject == @subject || subject.class <= @subject end def matches_conditions?(subject) if @block @block.call(subject) else matches_hash_conditions?(subject) end end def matches_hash_conditions?(subject) @conditions.each_pair do |name, value| return false if subject.send(name) != value end true end def eql?(other) other.class == self.class && @action == other.action && @subject == other.subject && @granted == other.granted end def ==(other) eql?(other) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
access-granted-0.2.1 | lib/access-granted/permission.rb |
access-granted-0.2 | lib/access-granted/permission.rb |
access-granted-0.1.1 | lib/access-granted/permission.rb |