Class: Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/zooline/credentials.rb

Constant Summary collapse

CRED_FILE =
"#{ENV['HOME']}/.zoocred"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil) ⇒ Credentials

Returns a new instance of Credentials.



6
7
8
9
10
11
12
13
# File 'lib/zooline/credentials.rb', line 6

def initialize(username = nil, password = nil)
  if !username.nil? && !password.nil?
    @username = username
    @password = password
  else
    open
  end
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



2
3
4
# File 'lib/zooline/credentials.rb', line 2

def password
  @password
end

#usernameObject

Returns the value of attribute username.



2
3
4
# File 'lib/zooline/credentials.rb', line 2

def username
  @username
end

Class Method Details

.check?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/zooline/credentials.rb', line 34

def self.check?
  File.exist? CRED_FILE
end

.wipeout!Object



30
31
32
# File 'lib/zooline/credentials.rb', line 30

def self.wipeout!
  FileUtils.rm CRED_FILE
end

Instance Method Details

#openObject



22
23
24
25
26
27
28
# File 'lib/zooline/credentials.rb', line 22

def open
 File.open(CRED_FILE, "r") do |reado|
   content = reado.gets.split(",")
   @username = content.first
   @password = content.last
 end 
end

#save!Object



15
16
17
18
19
20
# File 'lib/zooline/credentials.rb', line 15

def save!
  FileUtils.touch CRED_FILE
  save = File.new(CRED_FILE, "w")
  save.write([@username, Digest::SHA1.hexdigest(@password)].join(","))
  save.close
end