Class: HW::Sources
- Inherits:
-
Thor
show all
- Extended by:
- Actions, Thor::Actions, Thor::Shell
- Defined in:
- lib/hw/sources.rb
Constant Summary
collapse
- @@sources =
{}
Class Method Summary
collapse
Methods included from Actions
bundle, error, git, header, info, migrate, migration, pbcopy, pbpaste, rake, replace_file, success, warn, worker
Class Method Details
.add(name, source) ⇒ Object
25
26
27
28
29
|
# File 'lib/hw/sources.rb', line 25
def add name, source
self.destination_root = "."
"Appending #{name} to #{CONFIG_PATH}"
append_file CONFIG_PATH, "#{name}=#{source}\n"
end
|
.all ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/hw/sources.rb', line 12
def all
if File.exists? CONFIG_PATH
File.readlines(CONFIG_PATH).each do |line|
source = line.split("=")
path = source[1].strip
path = File.expand_path(path) if local_source?(path)
@@sources[source[0]] = path
end
end
@@sources
end
|
.ensure_defaults ⇒ Object
.fetch ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/hw/sources.rb', line 44
def fetch
self.all.each do |name, url|
begin
path = "#{SOURCES_PATH}/#{name}"
local = self.local_source?(url)
unless local
if File.exists?(path)
Git.open(path, log: nil).lib.send(:command, 'pull') else
Git.clone(url, name, :path => SOURCES_PATH)
end
end
if local and !File.exists?(url)
error "Local directory '#{url}' not found. Please check your sources at #{CONFIG_PATH}"
else
success "Successfully pulled updates from #{url} to #{SOURCES_PATH}#{name}"
end
rescue Git::GitExecuteError
warn "Nothing was pulled from #{url}"
end
end
end
|
.local_source?(path) ⇒ Boolean
69
70
71
72
|
# File 'lib/hw/sources.rb', line 69
def local_source? path
git_regex = /([A-Za-z0-9]+@|http(|s)\:\/\/)([A-Za-z0-9.]+)(:|\/)([A-Za-z0-9\-\/]+)/
(path =~ git_regex).nil?
end
|