Class: DeployGate::Commands::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/deploygate/commands/init.rb

Class Method Summary collapse

Class Method Details

.create_account(email) ⇒ void

This method returns an undefined value.

Parameters:

  • email (String)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/deploygate/commands/init.rb', line 51

def (email)
  puts "Looks new to DeployGate. Let's set up your account, just choose your username and password."
  puts ''

  name = ()
  puts ''

  password = ()
  puts ''

  print 'Creating your account... '
  if DeployGate::User.create(name, email, password).nil?
    Message::Error.print('User create error')
    Message::Error.print('Please try again')
    raise 'User create error'
  else
    Message::Success.print('done! Your account has been set up successfully.')
    (email, password)
  end
end

.finishvoid

This method returns an undefined value.



105
106
107
# File 'lib/deploygate/commands/init.rb', line 105

def finish
  Message::Success.print('Enjoy development!')
end

.input_new_account_nameString

Returns:

  • (String)


73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/deploygate/commands/init.rb', line 73

def 
  user_name = ask("Username: " )
  print 'Checking for availability... '

  if DeployGate::User.registered?(user_name, '')
    Message::Error.print("Bad, #{user_name} is already used. Please try again.")
    return ()
  else
    Message::Success.print("Good, #{user_name} is available.")
    return user_name
  end
end

.input_new_account_passwordString

Returns:

  • (String)


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/deploygate/commands/init.rb', line 87

def 
  password = input_password('Password: ')
  secound_password = input_password('Type the same password: ')

  if password == secound_password
    return password
  else
    Message::Error.print("Password Please enter the same thing.")
    return ()
  end
end

.input_password(message) ⇒ String

Returns:

  • (String)


100
101
102
# File 'lib/deploygate/commands/init.rb', line 100

def input_password(message)
  ask(message) { |q| q.echo = "*" }
end

.login(email, password) ⇒ void

This method returns an undefined value.

Parameters:

  • email (String)
  • password (String)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/deploygate/commands/init.rb', line 34

def (email, password)
  begin
    Session.(email, password)
  rescue Session::LoginError => e
    # login failed
    Message::Error.print('Login failed...')
    Message::Error.print('Please try again')
    raise e
  end

  # login success
  session = Session.new
  Message::Success.print("Hello #{session.name}!")
end

.runvoid

This method returns an undefined value.



7
8
9
10
11
# File 'lib/deploygate/commands/init.rb', line 7

def run
  () unless Session.new().login?

  finish
end

.start_login_or_create_accountvoid

This method returns an undefined value.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/deploygate/commands/init.rb', line 14

def 
  puts 'Welcome to DeployGate!'
  puts ''
  email = ask("Email: ")

  puts ''
  puts 'Checking for your account...'
  if DeployGate::User.registered?('', email)
    puts ''
    password = input_password('Password: ')
    puts ''
    (email, password)
  else
    (email)
  end
end