Class: HW::Packages
- Inherits:
-
Object
show all
- Extended by:
- Actions, Thor::Actions, Thor::Shell
- Defined in:
- lib/hw/packages.rb
Constant Summary
collapse
- @@packages =
{}
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) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/hw/packages.rb', line 10
def add name
Sources.all.each do |key, path|
full_path = if HW::Sources.local_source?(path)
File.join(path, "#{name}.rb")
else
File.join(SOURCES_PATH, key, "#{name}.rb")
end
@@packages[name] = full_path if File.exists?(full_path)
end
if reserved?(name)
puts "'#{name}' is a reserved word and cannot be defined as a package"
exit(1)
end
register(name, @@packages[name])
end
|
55
56
57
|
# File 'lib/hw/packages.rb', line 55
def formatted_list
print_in_columns(Packages.list)
end
|
.list ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/hw/packages.rb', line 39
def list
"Listing available packages"
Sources.all.keys.each do |directory|
full_path = File.join(SOURCES_PATH, directory, "*.rb")
Dir[full_path].each do |file|
key = File.basename(file, '.rb')
@@packages[key] = file
end
end
@@packages.merge!({ 'system' => nil, 'help' => nil })
@@packages.keys.sort
end
|
.register(name, file) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/hw/packages.rb', line 29
def register name, file
raise LoadError if file.nil? require file
klass = Packages::const_get(name.to_pkg)
Thor.register(klass, name, "#{name} <command>", "")
rescue LoadError
puts "The package '#{name}' was not found in any of the sources"
exit(1)
end
|
.reserved?(name) ⇒ Boolean
59
60
61
|
# File 'lib/hw/packages.rb', line 59
def reserved? name
RESERVED_WORDS.include?(name.downcase)
end
|