Class: GitGo::Connection::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/git_go/connection/base.rb

Direct Known Subclasses

Local, Remote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/git_go/connection/base.rb', line 11

def initialize(core)
  @core         = core
  @current_path = ""
end

Instance Attribute Details

#coreGitGo::Core (readonly)

Returns instance.

Returns:



6
7
8
# File 'lib/git_go/connection/base.rb', line 6

def core
  @core
end

#current_pathString (readonly)

Returns the current path on the host.

Returns:

  • (String)

    the current path on the host.



9
10
11
# File 'lib/git_go/connection/base.rb', line 9

def current_path
  @current_path
end

Instance Method Details

#cd(path) ⇒ String

Moves the instance to the provided path and remembers it for the next action performed through the #bash method. It keeps the current path in #current_path

Parameters:

  • path (String)

    the path to navigate to.

Returns:

  • (String)

    the new path.

See Also:



24
25
26
# File 'lib/git_go/connection/base.rb', line 24

def cd(path)
  @current_path = bash("cd '#{current_path}'; cd '#{path}'; pwd")[:stdout].chomp
end

#close_and_exit(code = 0) ⇒ Object

Closes the connection and exits the program with CODE.

Parameters:

  • code (Integer) (defaults to: 0)

    the code to exit the program with.

See Also:

  • #close


83
84
85
86
# File 'lib/git_go/connection/base.rb', line 83

def close_and_exit(code = 0)
  close
  exit(code)
end

#directory?(path) ⇒ true, false

Tests to see whether the provided path is a directory. It will take the path relative from #current_path if no absolute path was provided.

Parameters:

  • path (String)

    the path to test.

Returns:

  • (true, false)


34
35
36
# File 'lib/git_go/connection/base.rb', line 34

def directory?(path)
  bash("[ -d '#{path}' ]")[:exit_code] == 0
end

#file?(path) ⇒ true, false

Tests to see whether the provided path is a file. It will take the path relative from #current_path if no absolute path was provided.

Parameters:

  • path (String)

    the path to test.

Returns:

  • (true, false)


44
45
46
# File 'lib/git_go/connection/base.rb', line 44

def file?(path)
  bash("[ -f '#{path}' ]")[:exit_code] == 0
end

#mkdir(path) ⇒ Hash

Creates a directory at the provided path. It will take the path relative from #current_path if no absolute path was provided.

Parameters:

  • path (String)

    the path to create one or more directories for.

Returns:

  • (Hash)

    containing #bash response data.



54
55
56
# File 'lib/git_go/connection/base.rb', line 54

def mkdir(path)
  bash("mkdir -p '#{path}'")
end

#mv(path, new_path) ⇒ Hash

Moves a file or directory from the PATH to the NEW_PATH. It will take the path relative from #current_path if no absolute path was provided.

Parameters:

  • path (String)

    the path to the file or directory to move.

  • new_path (String)

    the path to where the new file or directory should be placed.

Returns:

  • (Hash)

    containing #bash response data.



75
76
77
# File 'lib/git_go/connection/base.rb', line 75

def mv(path, new_path)
  bash("mv '#{path}' '#{new_path}'")
end

#rm(path) ⇒ Hash

Removes a file or directory at the provided path. It will take the path relative from #current_path if no absolute path was provided.

Parameters:

  • path (String)

    the path to the file or directory to remove.

Returns:

  • (Hash)

    containing #bash response data.



64
65
66
# File 'lib/git_go/connection/base.rb', line 64

def rm(path)
  bash("rm -rf '#{path}'")
end