Class: ClassicApi::Command::Users

Inherits:
Base
  • Object
show all
Defined in:
lib/classic_api/command/users.rb

Instance Method Summary collapse

Methods inherited from Base

api, handle_argument_error, start

Instance Method Details

#createObject

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
# File 'lib/classic_api/command/users.rb', line 20

def create()
  # Validate arguments
  raise ArgumentError, "invalid name '#{options.name}'. May only contain lowercase and digit characters." if !(options.name =~ /^[a-z0-9]+$/)
  raise ArgumentError, "invalid role '#{options.role}'. May only contain values 'admin' or 'default'." if !["admin", "default"].include?(options.role)
  raise ArgumentError, "invalid root path '#{options.root_path}'. Must be a path pattern with trailing slash." if options.root_path and !(options.root_path =~ %r{\A[a-z0-9/_-]+\/\z})
  
  # Create user
  user = api.users.create!(options)
  present user
end

#get(id) ⇒ Object



11
12
13
14
# File 'lib/classic_api/command/users.rb', line 11

def get(id)
  user = api.users.find(id)
  present(user)
end

#listObject



5
6
7
8
# File 'lib/classic_api/command/users.rb', line 5

def list
  users = api.users.all
  present(users)
end

#update(id) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/classic_api/command/users.rb', line 35

def update(id)
  # Validate arguments
  raise ArgumentError, "invalid name '#{options.name}'. May only contain lowercase and digit characters." if options.name and !(options.name =~ /^[a-z0-9]+$/)
  raise ArgumentError, "invalid role '#{options.role}'. May only contain values 'admin' or 'default'." if options.role and !["admin", "default"].include?(options.role)
  raise ArgumentError, "invalid root path '#{options.root_path}'. Must be a path pattern with trailing slash." if options.root_path and !(options.root_path =~ %r{\A[a-z0-9/_-]+\/\z})
  
  # Find user
  user = api.users.find(id)
  
  # Update user
  user.update_attributes(options)
  present user
end