class JiraMule::Passwords

Public Class Methods

new(path) click to toggle source
# File lib/jiraMule/Passwords.rb, line 12
def initialize(path)
  path = Pathname.new(path) unless path.kind_of? Pathname
  @path = path
  @data = nil
end

Public Instance Methods

get(host, user) click to toggle source
# File lib/jiraMule/Passwords.rb, line 45
def get(host, user)
  return nil unless @data.kind_of? Hash
  return nil unless @data.has_key? host
  return nil unless @data[host].kind_of? Hash
  return nil unless @data[host].has_key? user
  return @data[host][user]
end
load() click to toggle source
# File lib/jiraMule/Passwords.rb, line 17
def load()
  if @path.exist? then
    @path.chmod(0600)
    @path.open('rb') do |io|
      @data = YAML.load(io)
    end
  end
end
save() click to toggle source
# File lib/jiraMule/Passwords.rb, line 25
def save()
  @path.dirname.mkpath unless @path.dirname.exist?
  @path.open('wb') do |io|
    io << @data.to_yaml
  end
  @path.chmod(0600)
end
set(host, user, pass) click to toggle source
# File lib/jiraMule/Passwords.rb, line 32
def set(host, user, pass)
  unless @data.kind_of? Hash then
    @data = {host=>{user=>pass}}
    return
  end
  hd = @data[host]
  if hd.nil? or not hd.kind_of?(Hash) then
    @data[host] = {user=>pass}
    return
  end
  @data[host][user] = pass
  return
end