Class: Giticious::Service::User

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

Instance Method Summary collapse

Instance Method Details

#create(username) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/giticious/service/user.rb', line 18

def create(username)
  if Giticious::Model::User.find_by_username(username).nil? == false
    raise ArgumentError, "a user with this name does already exist"
  end

  user = Giticious::Model::User.new
  user.username = username

  user.save!
end

#delete_by_username(username) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/giticious/service/user.rb', line 29

def delete_by_username(username)
  user = Giticious::Model::User.find_by_username(username)

  if user.nil?
    raise ArgumentError, "The selected user does not exist"
  end

  Giticious::Model::Permission.where(user_id: user.id).delete_all

  user.destroy!
end

#exists?(username) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/giticious/service/user.rb', line 41

def exists?(username)
  Giticious::Model::User.find_by_username(username).nil? == false
end

#listObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/giticious/service/user.rb', line 5

def list
  users = []

  Giticious::Model::User.all.each do |user|
    users << {
      id: user.id,
      username: user.username,
    }
  end

  users
end