Class: RailsDocks::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/railsdocks/config.rb

Constant Summary collapse

DIRECTORY =
File.expand_path("~/.config/railsdocks")
FILE_PATH =
File.join(DIRECTORY, "config.json")

Class Method Summary collapse

Class Method Details

.emailObject



31
32
33
34
35
# File 'lib/railsdocks/config.rb', line 31

def self.email
  data.fetch("email")
rescue Errno::ENOENT, KeyError, JSON::ParserError
  nil
end

.logged_in?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/railsdocks/config.rb', line 37

def self.logged_in?
  token.to_s != ""
end

.save_login(email:, token:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/railsdocks/config.rb', line 11

def self.(email:, token:)
  FileUtils.mkdir_p(DIRECTORY)

  File.write(
    FILE_PATH,
    JSON.pretty_generate(
      email: email,
      token: token
    )
  )

  File.chmod(0o600, FILE_PATH)
end

.tokenObject



25
26
27
28
29
# File 'lib/railsdocks/config.rb', line 25

def self.token
  data.fetch("token")
rescue Errno::ENOENT, KeyError, JSON::ParserError
  nil
end