Module: GetGithubPubKeys::Files

Included in:
Client
Defined in:
lib/get_github_pub_keys/files.rb

Constant Summary collapse

DEFAULT_SSH_DIRECTORY =
"/#{ENV["HOME"]}/.ssh".freeze
DEFAULT_IDENTIFY =
'.pub'.freeze

Class Method Summary collapse

Class Method Details

.create(file_name, body) ⇒ Object

public_keys file create to .ssh directory.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/get_github_pub_keys/files.rb', line 9

def self.create(file_name, body)
  file_name = file_name.to_s
  file_name = File.basename(file_name)
  file_name = file_name + "_" + Time.now.strftime("%Y%0m%0d%0H%0M%0S") + DEFAULT_IDENTIFY
  body = body.gsub("\n","") # TODO: Windows動作未確認
  File.open(DEFAULT_SSH_DIRECTORY + "/" + file_name, "w") do |file|
    file.puts body
  end
  puts "Create public_key file: #{file_name}."
rescue => e
  # FIXME: 例外処理
  puts e.message
  nil
end