Class: Pendaxes::Workspace
- Inherits:
-
Object
- Object
- Pendaxes::Workspace
show all
- Extended by:
- Defaults
- Defined in:
- lib/pendaxes/workspace.rb
Defined Under Namespace
Classes: RemoteUrlMissing
Instance Method Summary
collapse
Methods included from Defaults
defaults
Constructor Details
#initialize(config = {}) ⇒ Workspace
Returns a new instance of Workspace.
8
9
10
|
# File 'lib/pendaxes/workspace.rb', line 8
def initialize(config={})
@config = Hashr.new(self.class.defaults.merge(config))
end
|
Instance Method Details
#clone ⇒ Object
12
13
14
15
16
|
# File 'lib/pendaxes/workspace.rb', line 12
def clone
raise RemoteUrlMissing, "Set git remote url to workspace.repository, or clone to path yourself." unless @config.repository
FileUtils.remove_entry_secure(path) if File.exist?(path)
git "clone", @config.repository, path
end
|
#dive ⇒ Object
29
30
31
32
33
|
# File 'lib/pendaxes/workspace.rb', line 29
def dive
Dir.chdir(path) do
yield
end
end
|
#git(*args) ⇒ Object
35
36
37
38
|
# File 'lib/pendaxes/workspace.rb', line 35
def git(*args)
str = IO.popen([@config.git || "git", *args], 'r', &:read)
$?.success? ? str : nil
end
|
#path ⇒ Object
27
|
# File 'lib/pendaxes/workspace.rb', line 27
def path; @config.path; end
|
#update ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/pendaxes/workspace.rb', line 18
def update
clone unless File.exist?(path)
dive do
git "fetch", "origin"
git "reset", "--hard", @config.branch || "origin/HEAD"
end
end
|