Class: Mxrb::TeamServer::Credentials
- Inherits:
-
Object
- Object
- Mxrb::TeamServer::Credentials
- Defined in:
- lib/mxrb/team_server.rb
Overview
Stores only a reference to a user-managed PAT file.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #configure_pat_file(source) ⇒ Object
-
#initialize(path: nil, pat_file: ENV['MXRB_TEAM_SERVER_PAT_FILE']) ⇒ Credentials
constructor
A new instance of Credentials.
- #pat ⇒ Object
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.(path || File.join(base, 'mxrb', 'credentials')) @pat_file = (pat_file) end |
Instance Attribute Details
#path ⇒ Object (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
29 30 31 32 33 34 35 36 37 |
# File 'lib/mxrb/team_server.rb', line 29 def configure_pat_file(source) @pat_file = (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 |
#pat ⇒ Object
39 40 41 42 43 |
# File 'lib/mxrb/team_server.rb', line 39 def pat source = @pat_file source ||= (read_config['team_server_pat_file']) if File.file?(@path) source && read_pat_file(source) end |