Sha256: c0b6b941f9e17459b1df58b9fd8d9a98b8cab4207637e13b5466d6bcb1dde77b
Contents?: true
Size: 794 Bytes
Versions: 18
Compression:
Stored size: 794 Bytes
Contents
require 'cancan' class WCC::Auth::TieredAbility include CanCan::Ability def initialize(user) @user = user grant_access_at(@user.access_level) end def grant_access_at(access_level) levels.each do |level, can_blocks| if access_level >= level can_blocks.each { |can_block| instance_exec(@user, &can_block) } end end end def levels self.class.levels end def self.at_level(level_key, &can_block) level = WCC::Auth::AccessLevel[level_key] or raise ArgumentError, "#{level_key} is not a valid access level" levels[level] << can_block end def self.levels @levels ||= Hash.new { |hash, key| hash[key] = [] } end def self.inherited(subclass) subclass.send :instance_variable_set, :@levels, levels.dup end end
Version data entries
18 entries across 18 versions & 1 rubygems