Class: GitSSHWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/git-ssh-wrapper.rb,
lib/git-ssh-wrapper/version.rb

Defined Under Namespace

Classes: CLI, PrivateKeyRequired

Constant Summary collapse

SAFE_MODE =
0600
EXEC_MODE =
0700
VERSION =
'0.2.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GitSSHWrapper

Returns a new instance of GitSSHWrapper.



32
33
34
35
36
37
38
39
40
41
# File 'lib/git-ssh-wrapper.rb', line 32

def initialize(options)
  if options[:private_key_path].to_s.empty? && options[:private_key].to_s.empty?
    raise PrivateKeyRequired
  end

  log_level  = (options[:log_level] || 'INFO').upcase
  @tempfiles = []
  key_path   = options[:private_key_path] || tempfile(options[:private_key])
  @path      = script(key_path, log_level)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



30
31
32
# File 'lib/git-ssh-wrapper.rb', line 30

def path
  @path
end

Class Method Details

.run(command, options) ⇒ Object

command given as an array for Kernel#system



16
17
18
19
20
21
# File 'lib/git-ssh-wrapper.rb', line 16

def self.run(command, options)
  with_wrapper(options) do |wrapper|
    wrapper.set_env
    system *command
  end
end

.with_wrapper(options) ⇒ Object



23
24
25
26
27
28
# File 'lib/git-ssh-wrapper.rb', line 23

def self.with_wrapper(options)
  wrapper = new(options)
  yield wrapper
ensure
  wrapper.unlink
end

Instance Method Details

#cmd_prefixObject Also known as: git_ssh



47
48
49
# File 'lib/git-ssh-wrapper.rb', line 47

def cmd_prefix
  "GIT_SSH='#{path}'"
end

#pathnameObject



43
44
45
# File 'lib/git-ssh-wrapper.rb', line 43

def pathname
  Pathname.new(path)
end

#set_envObject



52
53
54
55
# File 'lib/git-ssh-wrapper.rb', line 52

def set_env
  @old_git_ssh = ENV['GIT_SSH']
  ENV['GIT_SSH'] = path
end


61
62
63
64
# File 'lib/git-ssh-wrapper.rb', line 61

def unlink
  unset_env
  @tempfiles.each { |file| file.unlink }.clear
end

#unset_envObject



57
58
59
# File 'lib/git-ssh-wrapper.rb', line 57

def unset_env
  ENV['GIT_SSH'] = @old_git_ssh
end