Class: RubyNative::CLI::Credentials
- Inherits:
-
Object
- Object
- RubyNative::CLI::Credentials
- 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
.clear ⇒ Object
27 28 29 |
# File 'lib/ruby_native/cli/credentials.rb', line 27 def self.clear File.delete(PATH) if File.exist?(PATH) end |
.file_token ⇒ Object
13 14 15 16 17 18 |
# File 'lib/ruby_native/cli/credentials.rb', line 13 def self.file_token return unless File.exist?(PATH) JSON.parse(File.read(PATH))["token"] rescue JSON::ParserError nil end |
.save(token) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ruby_native/cli/credentials.rb', line 20 def self.save(token) dir = File.dirname(PATH) FileUtils.mkdir_p(dir) File.write(PATH, JSON.generate(token: token)) File.chmod(0600, PATH) end |
.token ⇒ Object
9 10 11 |
# File 'lib/ruby_native/cli/credentials.rb', line 9 def self.token ENV["RUBY_NATIVE_TOKEN"] || file_token end |