Class: Lipaste::Config

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

Constant Summary collapse

FILE_NAME =
".lipaste"

Class Method Summary collapse

Class Method Details

._create_config(username, password) ⇒ Object



40
41
42
43
# File 'lib/lipaste/config.rb', line 40

def self._create_config(username, password)
  data = {username: username, password: password}
  File.write get_path, data.to_yaml
end

.create_configObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lipaste/config.rb', line 27

def self.create_config
  puts "Your credentials will only be stored locally on your computer."
  print "Username: "
  username = $stdin.gets.chomp

  print "Password (text will be hidden): "
  `stty -echo`
  password = $stdin.gets.chomp
  `stty echo`

  _create_config username, password
end

.destroyObject



23
24
25
# File 'lib/lipaste/config.rb', line 23

def self.destroy
  File.delete get_path if exists?
end

.exists?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/lipaste/config.rb', line 19

def self.exists?
  File.exists? get_path
end

.get_pathObject



14
15
16
17
# File 'lib/lipaste/config.rb', line 14

def self.get_path
  home = File.expand_path "~"
  File.join home, FILE_NAME
end

.readObject



7
8
9
10
11
12
# File 'lib/lipaste/config.rb', line 7

def self.read
  return nil unless exists?

  content = File.read get_path
  YAML.load content
end