Class: Morale::Account

Inherits:
Object
  • Object
show all
Extended by:
CredentialsStore, Flow
Includes:
IO
Defined in:
lib/morale/account.rb

Instance Attribute Summary

Attributes included from CredentialsStore

#credentials

Class Method Summary collapse

Methods included from Flow

retryable

Methods included from CredentialsStore

default_location, delete_credentials, location, location=, read_credentials, write_credentials

Methods included from IO

#ask, #ask_for_secret, #ask_for_secret_on_windows, #echo_off, #echo_on, #say

Class Method Details

.api_keyObject



27
28
29
30
# File 'lib/morale/account.rb', line 27

def api_key
  get_credentials
  @credentials[1]
end

.get_credentials(ask = true) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/morale/account.rb', line 49

def get_credentials(ask=true)
  return if @credentials
  unless @credentials = read_credentials
    ask_for_and_save_credentials if ask
  end
  @credentials
end

.project(ask = true) ⇒ Object



32
33
34
35
# File 'lib/morale/account.rb', line 32

def project(ask=true)
  get_credentials ask
  @credentials[2] if !@credentials.nil? && @credentials.length > 2
end

.project=(value) ⇒ Object



37
38
39
40
41
# File 'lib/morale/account.rb', line 37

def project=(value)
  @credentials ||= Array.new(3)
  @credentials[2] = value
  write_credentials
end

.retry_login?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/morale/account.rb', line 43

def retry_login?
  @login_attempts ||= 0
  @login_attempts += 1
  @login_attempts < 3
end

.subdomain(ask = true) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/morale/account.rb', line 12

def subdomain(ask=true)
  if @subdomain.nil?
    get_credentials ask
    @subdomain = @credentials[0]
  end
  @subdomain
end

.subdomain=(value) ⇒ Object



20
21
22
23
24
25
# File 'lib/morale/account.rb', line 20

def subdomain=(value)
  @subdomain = value
  @credentials ||= []
  @credentials[0] = value
  write_credentials
end