class Yus::Privilege
Attributes
expiry_time[W]
Public Class Methods
new()
click to toggle source
# File lib/yus/privilege.rb, line 7 def initialize @items = {} end
Public Instance Methods
expiry_time(item=:everything)
click to toggle source
# File lib/yus/privilege.rb, line 10 def expiry_time(item=:everything) if(time = [@items[item], @items[:everything]].compact.max) time if time.is_a?(Time) else raise NotPrivilegedError end end
grant(item, expiry_time=:never)
click to toggle source
# File lib/yus/privilege.rb, line 17 def grant(item, expiry_time=:never) @items.store(item, expiry_time) end
granted?(item)
click to toggle source
# File lib/yus/privilege.rb, line 20 def granted?(item) if(expiry_time = @items[item]) case expiry_time when Time Time.now < expiry_time else true end elsif(@items.include?(:everything)) # check time granted?(:everything) else item = item.to_s.dup if(item[-1] != ?*) while(!item.empty?) item.slice!(/[^.]*$/) if(granted?(item + "*")) return true end item.chop! end end false end end
info()
click to toggle source
# File lib/yus/privilege.rb, line 45 def info @items.collect { |item, time| info = [item.to_s] if time.is_a?(Time) info.push time end info }.sort end
revoke(item, expiry_time=nil)
click to toggle source
# File lib/yus/privilege.rb, line 54 def revoke(item, expiry_time=nil) case expiry_time when Time @items.store(item, expiry_time) else @items.delete(item) end end