Module: Permissive::Permissions

Defined in:
lib/permissive/permissions.rb

Class Method Summary collapse

Class Method Details

.const_set(*args) ⇒ Object



7
8
9
10
# File 'lib/permissive/permissions.rb', line 7

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

.hashObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/permissive/permissions.rb', line 12

def hash
  @@hash ||= begin
    bitwise_hash = constants.inject({}) do |hash, constant_name|
      hash[constant_name.downcase] = 2 ** Permissive::Permissions.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 ArgumentError
    raise Permissive::PermissionError.new("Permissions must be integers or longs. Strings, symbols, and floats are not currently supported.")
  end
end