Sha256: c07153446e7a30bda54a50bbaa00ddaf5f324b5164ce38fd4fd012e358db31c3

Contents?: true

Size: 679 Bytes

Versions: 31

Compression:

Stored size: 679 Bytes

Contents

# frozen_string_literal: true

require 'json'
require 'uffizzi/helpers/file_helper'

module Uffizzi
  class Token
    TOKEN_PATH = "#{Dir.home}/.config/uffizzi/token"

    class << self
      def token_path
        TOKEN_PATH
      end

      def delete
        File.truncate(token_path, 0) if exists?
      end

      def exists?
        File.exist?(token_path) && !read.nil?
      end

      def read
        content = File.read(token_path)
        content.presence
      rescue Errno::ENOENT
        nil
      end

      def write(token)
        return nil unless token.is_a?(String)

        Uffizzi::FileHelper.write_with_lock(token_path, token)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
uffizzi-cli-2.4.11 lib/uffizzi/token.rb
uffizzi-cli-2.4.10 lib/uffizzi/token.rb
uffizzi-cli-2.4.9 lib/uffizzi/token.rb
uffizzi-cli-2.4.8 lib/uffizzi/token.rb
uffizzi-cli-2.4.7 lib/uffizzi/token.rb
uffizzi-cli-2.4.6 lib/uffizzi/token.rb
uffizzi-cli-2.4.5 lib/uffizzi/token.rb
uffizzi-cli-2.4.4 lib/uffizzi/token.rb
uffizzi-cli-2.4.3 lib/uffizzi/token.rb
uffizzi-cli-2.4.2 lib/uffizzi/token.rb
uffizzi-cli-2.4.1 lib/uffizzi/token.rb
uffizzi-cli-2.4.0 lib/uffizzi/token.rb
uffizzi-cli-2.3.4 lib/uffizzi/token.rb
uffizzi-cli-2.3.3 lib/uffizzi/token.rb
uffizzi-cli-2.3.2 lib/uffizzi/token.rb
uffizzi-cli-2.3.1 lib/uffizzi/token.rb
uffizzi-cli-2.3.0 lib/uffizzi/token.rb
uffizzi-cli-2.2.2 lib/uffizzi/token.rb
uffizzi-cli-2.2.1 lib/uffizzi/token.rb
uffizzi-cli-2.2.0 lib/uffizzi/token.rb