Class: Mxrb::TeamServer::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/team_server.rb

Overview

Stores only a reference to a user-managed PAT file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, pat_file: ENV['MXRB_TEAM_SERVER_PAT_FILE']) ⇒ Credentials

Returns a new instance of Credentials.



22
23
24
25
26
27
# File 'lib/mxrb/team_server.rb', line 22

def initialize(path: nil, pat_file: ENV['MXRB_TEAM_SERVER_PAT_FILE'])
  base = ENV['XDG_CONFIG_HOME'].to_s
  base = File.join(Dir.home, '.config') if base.empty?
  @path = File.expand_path(path || File.join(base, 'mxrb', 'credentials'))
  @pat_file = expand(pat_file)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/mxrb/team_server.rb', line 20

def path
  @path
end

Instance Method Details

#configure_pat_file(source) ⇒ Object

Raises:



29
30
31
32
33
34
35
36
37
# File 'lib/mxrb/team_server.rb', line 29

def configure_pat_file(source)
  @pat_file = expand(source)
  raise TeamServerError, 'Team Server PAT file path must not be empty' unless @pat_file

  read_pat_file(@pat_file)
  config = File.file?(@path) ? read_config : {}
  config.delete('team_server_pat')
  write_config(config.merge('team_server_pat_file' => @pat_file))
end

#patObject



39
40
41
42
43
# File 'lib/mxrb/team_server.rb', line 39

def pat
  source = @pat_file
  source ||= expand(read_config['team_server_pat_file']) if File.file?(@path)
  source && read_pat_file(source)
end