Module: ActsPermissive::PermissionMap

Defined in:
lib/acts_permissive/permission_map.rb

Class Method Summary collapse

Class Method Details

.const_set(*args) ⇒ Object



4
5
6
7
# File 'lib/acts_permissive/permission_map.rb', line 4

def const_set(*args)
  @@hash = nil
  super
end

.hashObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/acts_permissive/permission_map.rb', line 9

def hash
  @@hash ||= begin
    bitwise_hash = constants.inject({}) do |hash, constant_name|
      hash[constant_name.downcase] = 2 ** ActsPermissive::PermissionMap.const_get(constant_name.to_sym)
      hash
    end
    inverted_hash = bitwise_hash.invert
    bitwise_hash.values.sort.inject(ActiveSupport::OrderedHash.new) do |hash, value|
      hash[inverted_hash[value].to_sym] = value
      hash
    end
  rescue TypeError
    raise ActsPermissive::PermissiveError.new("Permissions must be integers or longs. Strings, symbols, and floats are not currently supported.")
  end
end