Sha256: 46a5634a3e8a3406f9be4f0143b1a3572deccb8c4b876f05bf0188b5ab04b955

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

# coding: utf-8
require 'logger'

module GetGithubPubKeys
  module Files
    DEFAULT_SSH_DIRECTORY = "/#{ENV["HOME"]}/.ssh".freeze
    DEFAULT_IDENTIFY = '.pub'.freeze
    attr_accessor :path
    #
    # This method confirm exists .ssh directory. 
    def ssh_exists?
      File.exists(DEFAULT_SSH_DIRECTORY)
    end
    #
    # create /HOME_DIRECOTY/.ssh directory
    def ssh_create
      Dir.mkdir("#{ENV["HOME"]}/#{DEFAULT_SSH_DIRECTORY}")
    end

    # public_keys file create to .ssh directory.
    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","")
      File.open(DEFAULT_SSH_DIRECTORY + "/" + file_name, "w") do |file|
        file.puts body
      end
      puts "Create public_key file: #{file_name}."
    rescue => e
      puts e.message
      nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
get_github_pub_keys-0.0.2 lib/get_github_pub_keys/files.rb
get_github_pub_keys-0.0.1 lib/get_github_pub_keys/files.rb