Sha256: d3343ea4300c2a7c17356b35e29b3b51730723d5ee560810f36ea0bfcc31e73e

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

module Amp
  module Servers
    
    ##
    # = User
    # A single user within an Amp's server system. Just a simple struct -
    # though they do offer a convenient constructor, taking a hash.
    class User < Struct.new(:username, :password)
      
      ##
      # Generates a public user - i.e., somebody who has been granted no explicit rights.
      # @return [User] a public user with no explicit rights
      def self.public_user
        @@public_user ||= new('public', "")
      end
      
      ##
      # Extra constructor - takes a hash to create a new User, instead of
      # the Struct class's ordered parameters for its constructor.
      #
      # @raise [RuntimeError] raised if the user doesn't supply :password or
      #   :password_hashed
      # @param [Hash] input the hash representing the values for the struct
      # @option input [String] :username The username for the user
      # @option input [String] :password The cleartext (unencrypted) password.
      # @option input [String] :can_read Can the user read the repository?
      # @option input [String] :can_write Can the user write to the repository?
      def self.from_hash(input={})
        # input checking
        unless input[:password]
          raise "User must have a password attribute"
        end
        
        # public is reserved as the username of the public user
        if input[:username].to_s == 'public'
          raise "User cannot have username 'public' -- reserved by Amp system"
        end
        
        new input[:username], input[:password]
      end
      
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
amp-0.5.3 lib/amp/server/amp_user.rb
amp-0.5.2 lib/amp/server/amp_user.rb
amp-0.5.1 lib/amp/server/amp_user.rb
amp-pure-0.5.0 lib/amp/server/amp_user.rb
amp-0.5.0 lib/amp/server/amp_user.rb