Class: GitGo::Connection::Base
- Inherits:
-
Object
- Object
- GitGo::Connection::Base
- Defined in:
- lib/git_go/connection/base.rb
Instance Attribute Summary collapse
-
#core ⇒ GitGo::Core
readonly
Instance.
-
#current_path ⇒ String
readonly
The current path on the host.
Instance Method Summary collapse
-
#cd(path) ⇒ String
Moves the instance to the provided path and remembers it for the next action performed through the #bash method.
-
#close_and_exit(code = 0) ⇒ Object
Closes the connection and exits the program with CODE.
-
#directory?(path) ⇒ true, false
Tests to see whether the provided path is a directory.
-
#file?(path) ⇒ true, false
Tests to see whether the provided path is a file.
-
#initialize(core) ⇒ Base
constructor
A new instance of Base.
-
#mkdir(path) ⇒ Hash
Creates a directory at the provided path.
-
#mv(path, new_path) ⇒ Hash
Moves a file or directory from the PATH to the NEW_PATH.
-
#rm(path) ⇒ Hash
Removes a file or directory at the provided path.
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
#core ⇒ GitGo::Core (readonly)
Returns instance.
6 7 8 |
# File 'lib/git_go/connection/base.rb', line 6 def core @core end |
#current_path ⇒ String (readonly)
Returns 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
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.
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.
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.
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.
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.
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.
64 65 66 |
# File 'lib/git_go/connection/base.rb', line 64 def rm(path) bash("rm -rf '#{path}'") end |