Sha256: 4d5456b5d7bb85fd300d30367ff338b2e2e220c8d94cbb6f04d46b4de7f275f0

Contents?: true

Size: 857 Bytes

Versions: 9

Compression:

Stored size: 857 Bytes

Contents

# encoding: UTF-8

require 'securerandom'

module Spontaneous
  module Permissions

    autoload :UserLevel, "spontaneous/permissions/user_level"
    autoload :User, "spontaneous/permissions/user"
    autoload :AccessGroup, "spontaneous/permissions/access_group"
    autoload :AccessKey, "spontaneous/permissions/access_key"

    class << self
      # Convenience shortcut so we can do Permissions[:root]
      def [](level_name)
        UserLevel[level_name]
      end

      def root
        UserLevel.root
      end

      def has_level?(user, level)
        return true unless user
        user.level >= level
      end

      def random_string(length)
        SecureRandom.urlsafe_base64(length)[0...(length)]
      end

      def crypto_hash(string, algorithm = Digest::SHA1)
        algorithm.new.update(string).hexdigest
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta9 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta8 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta7 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta6 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta5 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta4 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta3 lib/spontaneous/permissions.rb
spontaneous-0.2.0.beta2 lib/spontaneous/permissions.rb