Class: CslCli::Tokenstore

Inherits:
Object
  • Object
show all
Defined in:
lib/csl_cli/tokenstore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Tokenstore



11
12
13
14
# File 'lib/csl_cli/tokenstore.rb', line 11

def initialize(path)
  @path = path
  @tokenfile = File.join(@path, '.csl_token')
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/csl_cli/tokenstore.rb', line 9

def path
  @path
end

Instance Method Details

#clearObject



31
32
33
34
# File 'lib/csl_cli/tokenstore.rb', line 31

def clear
  File.delete(@tokenfile) if File.exist?(@tokenfile)
  return true
end

#loadObject



16
17
18
19
20
21
# File 'lib/csl_cli/tokenstore.rb', line 16

def load
  file = File.open(@tokenfile, 'rb')
  @saved_token = file.read()
  file.close
  return @saved_token
end

#store(token) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/csl_cli/tokenstore.rb', line 23

def store(token)
  file = File.open(@tokenfile, 'w')
  file.write(token)
  file.close
  File.chmod(0600, @tokenfile)
  return true
end