Class: Pgchief::Command::UserCreate

Inherits:
Base
  • Object
show all
Defined in:
lib/pgchief/command/user_create.rb

Overview

Class to create a user

Constant Summary collapse

USER_OPTIONS =
%w[
  NOINHERIT
  NOCREATEDB
  NOCREATEROLE
  NOSUPERUSER
  NOREPLICATION
].freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#conn, #params

Instance Method Summary collapse

Methods inherited from Base

call, #initialize

Constructor Details

This class inherits a constructor from Pgchief::Command::Base

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



15
16
17
# File 'lib/pgchief/command/user_create.rb', line 15

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



15
16
17
# File 'lib/pgchief/command/user_create.rb', line 15

def username
  @username
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pgchief/command/user_create.rb', line 17

def call
  @username, @password = params
  raise Pgchief::Errors::UserExistsError if user_exists?

  create_user!
  save_credentials!

  "User '#{username}' created successfully!"
rescue PG::Error => e
  "Error: #{e.message}"
ensure
  conn.close
end