Class: Cased::CLI::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/cased/cli/authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token: nil) ⇒ Authentication

Returns a new instance of Authentication.



11
12
13
14
15
# File 'lib/cased/cli/authentication.rb', line 11

def initialize(token: nil)
  @token = token || Cased.config.guard_user_token
  @directory = Pathname.new(File.expand_path('~/.cguard'))
  @credentials_path = @directory.join('credentials')
end

Instance Attribute Details

#credentials_pathObject (readonly)

Returns the value of attribute credentials_path.



8
9
10
# File 'lib/cased/cli/authentication.rb', line 8

def credentials_path
  @credentials_path
end

#directoryObject (readonly)

Returns the value of attribute directory.



8
9
10
# File 'lib/cased/cli/authentication.rb', line 8

def directory
  @directory
end

#tokenObject



21
22
23
24
25
26
27
# File 'lib/cased/cli/authentication.rb', line 21

def token
  @token ||= begin
    credentials_path.read
  rescue Errno::ENOENT
    nil
  end
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cased/cli/authentication.rb', line 17

def exists?
  !token.nil?
end