Class: RubyNative::CLI::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_native/cli/credentials.rb

Constant Summary collapse

PATH =
File.join(Dir.home, ".ruby_native", "credentials")

Class Method Summary collapse

Class Method Details

.clearObject



23
24
25
# File 'lib/ruby_native/cli/credentials.rb', line 23

def self.clear
  File.delete(PATH) if File.exist?(PATH)
end

.save(token) ⇒ Object



16
17
18
19
20
21
# File 'lib/ruby_native/cli/credentials.rb', line 16

def self.save(token)
  dir = File.dirname(PATH)
  FileUtils.mkdir_p(dir)
  File.write(PATH, JSON.generate(token: token))
  File.chmod(0600, PATH)
end

.tokenObject



9
10
11
12
13
14
# File 'lib/ruby_native/cli/credentials.rb', line 9

def self.token
  return unless File.exist?(PATH)
  JSON.parse(File.read(PATH))["token"]
rescue JSON::ParserError
  nil
end