class Sumodev::Commands::Push::AuthorizedKeys

Attributes

contents[R]

Public Class Methods

new(file_contents) click to toggle source
# File lib/sumodev/commands/push.rb, line 105
def initialize(file_contents)
  @contents = parse!(file_contents)
end

Public Instance Methods

add(key) click to toggle source
# File lib/sumodev/commands/push.rb, line 109
def add key
  @contents[key[:key]] = key
end
remove(key) click to toggle source
# File lib/sumodev/commands/push.rb, line 113
def remove key
  @contents.delete(key[:key])
end
to_io() click to toggle source
# File lib/sumodev/commands/push.rb, line 123
def to_io
  StringIO.new(to_s)
end
to_s() click to toggle source
# File lib/sumodev/commands/push.rb, line 117
def to_s
  @contents.collect do |identity, k|
    "#{k[:optional]}ssh-#{k[:protocol]} #{k[:key]} #{k[:identity]}\n"
  end.join
end

Private Instance Methods

parse!(file) click to toggle source
# File lib/sumodev/commands/push.rb, line 128
def parse! (file)
  file.split(/\n/).inject({}) do |hash, line|
    #hash[$4] = {:optional => $1, :protocol => $2, :key => $3, :identity => $4} if line =~ /^([^#]*?)ssh-(dss|rsa) (.*) ((.*?)@(.*))/
    hash[$3] = {:optional => $1, :protocol => $2, :key => $3, :identity => $4} if line =~ /^(\S*)ssh-(dss|rsa) (\S*)(?: (\S*))?$/
    hash
  end
end