Class: Zool::KeyfileWriter
- Inherits:
-
Object
- Object
- Zool::KeyfileWriter
- Defined in:
- lib/zool/key_file_writer.rb
Instance Attribute Summary collapse
-
#out_directory ⇒ Object
Returns the value of attribute out_directory.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(out_directory = 'keys') ⇒ KeyfileWriter
constructor
A new instance of KeyfileWriter.
- #logger ⇒ Object
- #write(key, outname = nil) ⇒ Object
- #write_keys(keys) ⇒ Object
Constructor Details
#initialize(out_directory = 'keys') ⇒ KeyfileWriter
Returns a new instance of KeyfileWriter.
18 19 20 |
# File 'lib/zool/key_file_writer.rb', line 18 def initialize(out_directory = 'keys') @out_directory = out_directory end |
Instance Attribute Details
#out_directory ⇒ Object
Returns the value of attribute out_directory.
6 7 8 |
# File 'lib/zool/key_file_writer.rb', line 6 def out_directory @out_directory end |
Class Method Details
.keyname_for_key(key) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/zool/key_file_writer.rb', line 8 def self.keyname_for_key(key) temp_name = key[/^\S*\s\S*\s([^@]+)\S*$/, 1] if temp_name.nil? logger.warn "key not parsable" '1__not_parsable' else temp_name.gsub(/[^A-Z|^a-z|^0-9]/, '_').downcase end end |
.logger ⇒ Object
40 41 42 |
# File 'lib/zool/key_file_writer.rb', line 40 def self.logger DEFAULT_LOGGER end |
Instance Method Details
#logger ⇒ Object
44 45 46 |
# File 'lib/zool/key_file_writer.rb', line 44 def logger DEFAULT_LOGGER end |
#write(key, outname = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/zool/key_file_writer.rb', line 28 def write(key, outname = nil) key_name = outname || self.class.keyname_for_key(key) key_count = Dir["#{out_directory}/#{key_name}*.pub"].size key_name += "_#{key_count + 1}" if key_count > 0 key_path = "#{out_directory}/#{key_name}.pub" File.open(key_path, 'w+') do |file| file.puts key end end |
#write_keys(keys) ⇒ Object
22 23 24 25 26 |
# File 'lib/zool/key_file_writer.rb', line 22 def write_keys(keys) keys.each do |key| write key end end |