class AuthorizedKeys::File
Attributes
location[RW]
Public Class Methods
new(location=nil)
click to toggle source
# File lib/authorized_keys/file.rb, line 8 def initialize(location=nil) self.location = location || "#{ENV['HOME']}/.ssh/authorized_keys" end
Public Instance Methods
add(key)
click to toggle source
# File lib/authorized_keys/file.rb, line 12 def add(key) key = Key.new(key) if key.is_a?(String) modify 'a+' do |file| file.puts key end end
remove(key)
click to toggle source
# File lib/authorized_keys/file.rb, line 20 def remove(key) key = Key.new(key) if key.is_a?(String) modify 'r' do |file| ::File.unlink(location) modify 'w' do |new_file| file.each do |line| new_file.puts line unless key == Key.new(line) new_file.flush end end end end
Private Instance Methods
modify(mode, &block)
click to toggle source
# File lib/authorized_keys/file.rb, line 36 def modify(mode, &block) ::File.open(location, mode, &block) end