Class: Keyman::User

Inherits:
Object
  • Object
show all
Defined in:
lib/keyman/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/keyman/user.rb', line 4

def key
  @key
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/keyman/user.rb', line 4

def name
  @name
end

Class Method Details

.add(name, key) ⇒ Object

Add a new user with the given details



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/keyman/user.rb', line 7

def self.add(name, key)
  existing = Keyman.users.select { |u| u.name == name.to_sym }.first
  if existing
    existing
  else
    if existing = Keyman.user_or_group_for(name)
      raise Error, "#{existing.class.to_s.split('::').last} already exists for '#{name}' - cannot define user with this name."
    end
    
    u = self.new
    u.name = name.to_sym
    u.key = key
    Keyman.users << u
    u
  end
end