Class: OpenUriAndWrite::Usernames
- Inherits:
-
Object
- Object
- OpenUriAndWrite::Usernames
- Defined in:
- lib/open-uri-and-write/usernames.rb
Instance Method Summary collapse
- #homedir ⇒ Object
- #read_usernames_and_hosts ⇒ Object
- #save_username_and_host(username, host) ⇒ Object
- #store_username_and_host(usernames) ⇒ Object
- #username_for_host(host) ⇒ Object
- #usernamesfile ⇒ Object
Instance Method Details
#homedir ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/open-uri-and-write/usernames.rb', line 7 def homedir if(Dir.respond_to?("home")) Dir.home else File.("~") end end |
#read_usernames_and_hosts ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/open-uri-and-write/usernames.rb', line 19 def read_usernames_and_hosts usernames = {} if(File.exist?(usernamesfile)) open(usernamesfile).readlines.each do |line| username, host = line.split(':') usernames[host.strip] = username.strip end end return usernames end |
#save_username_and_host(username, host) ⇒ Object
30 31 32 33 34 |
# File 'lib/open-uri-and-write/usernames.rb', line 30 def save_username_and_host(username,host) usernames = read_usernames_and_hosts usernames[host] = username store_username_and_host(usernames) end |
#store_username_and_host(usernames) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/open-uri-and-write/usernames.rb', line 36 def store_username_and_host(usernames) file = open(usernamesfile, "w") usernames.keys.each do |key| file.puts "#{usernames[key]}:#{key}" end file.close end |
#username_for_host(host) ⇒ Object
44 45 46 47 |
# File 'lib/open-uri-and-write/usernames.rb', line 44 def username_for_host(host) usernames = read_usernames_and_hosts return usernames[host] end |
#usernamesfile ⇒ Object
15 16 17 |
# File 'lib/open-uri-and-write/usernames.rb', line 15 def usernamesfile homedir + "/.open-uri-and-write-usernames" end |