Sha256: 646f29e6ebf812566256cf6b7d39a51863e3e486a52d271c29c2ed55e9bc3d4d
Contents?: true
Size: 735 Bytes
Versions: 2
Compression:
Stored size: 735 Bytes
Contents
module ReUser class Role def initialize *permissions @permissions = {} self.can *permissions end def can *permissions permissions.each do |permission| @permissions[permission] = lambda {|*args| true } end end def can? permission @permissions.has_key?(permission) && @permissions[permission].is_a?(Proc) end def could permission, &block raise "#could requires a block" unless block_given? @permissions[permission] = block end def could? permission, *block_args if @permissions.has_key?(permission) @permissions[permission].call(*block_args) else false end end alias_method :able_to?, :could? end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reuser-3.1.2 | lib/reuser/role.rb |
reuser-3.1.1 | lib/reuser/role.rb |