Sha256: 2e1a8c39a252f81c064e4802a406ddeadbe7290853fe6443d265152b08b2e5e8

Contents?: true

Size: 826 Bytes

Versions: 6

Compression:

Stored size: 826 Bytes

Contents

module ActsPermissive
  module PermissionMap
    class << self
      def const_set(*args)
        @@hash = nil
        super
      end

      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
acts_permissive-0.3.4 lib/acts_permissive/permission_map.rb
acts_permissive-0.3.3 lib/acts_permissive/permission_map.rb
acts_permissive-0.3.2 lib/acts_permissive/permission_map.rb
acts_permissive-0.3.1 lib/acts_permissive/permission_map.rb
acts_permissive-0.3.0 lib/acts_permissive/permission_map.rb
acts_permissive-0.2.5 lib/acts_permissive/permission_map.rb