Class: MsPac
- Inherits:
-
Object
show all
- Defined in:
- lib/mspac.rb
Defined Under Namespace
Classes: Error, PackageManager, Pellet, VersionControl
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hilight = false) ⇒ MsPac
Returns a new instance of MsPac.
55
56
57
58
59
60
61
62
|
# File 'lib/mspac.rb', line 55
def initialize(hilight = false)
@@hilight = hilight
FileUtils.mkdir_p(Pathname.new("~/.mspac").expand_path)
@mspac_dir = Pathname.new("~/.mspac").expand_path
@pm = PackageManager.new(self)
@vcs = VersionControl.new("git")
load_pellets
end
|
Class Method Details
.hilight? ⇒ Boolean
38
39
40
41
|
# File 'lib/mspac.rb', line 38
def self.hilight?
@@hilight ||= false
return @@hilight
end
|
Instance Method Details
#cached ⇒ Object
8
9
10
11
12
|
# File 'lib/mspac.rb', line 8
def cached
return @pellets.keys.sort.keep_if do |name|
@pellets[name].cached?
end
end
|
#clean ⇒ Object
14
15
16
17
18
19
|
# File 'lib/mspac.rb', line 14
def clean
@pellets.each do |name, pellet|
pellet.purge if (pellet.cached? && !pellet.installed?)
end
end
|
#install(pellets, force = false) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/mspac.rb', line 64
def install(pellets, force = false)
if (pellets.nil? || pellets.empty?)
raise Error::MissingPellet.new
end
pellets.each do |name|
if (@pellets.has_key?(name))
pellet = @pellets[name]
if (pellet.installed?)
pellet.update(force)
elsif (pellet.cached?)
pellet.link
pellet.update(true)
else
pellet.fetch
pellet.install
end
else
raise Error::MissingPellet.new(name)
end
end
end
|
#installed ⇒ Object
87
88
89
90
91
|
# File 'lib/mspac.rb', line 87
def installed
return @pellets.keys.sort.delete_if do |name|
!@pellets[name].installed?
end
end
|
#lock(pellets) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/mspac.rb', line 111
def lock(pellets)
if (pellets.nil? || pellets.empty?)
raise Error::MissingPellet.new
end
pellets.each do |name|
if (@pellets.has_key?(name))
@pellets[name].lock
else
raise Error::MissingPellet.new(name)
end
end
end
|
#pellets ⇒ Object
125
126
127
|
# File 'lib/mspac.rb', line 125
def pellets
return @pellets.keys.sort
end
|
#refresh ⇒ Object
129
130
131
132
133
134
|
# File 'lib/mspac.rb', line 129
def refresh
puts hilight_status("Refreshing pellets...")
Dir.chdir(@pellets_dir) do
@vcs.update
end
end
|
#remove(pellets, nosave) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/mspac.rb', line 136
def remove(pellets, nosave)
if (pellets.nil? || pellets.empty?)
raise Error::MissingPellet.new
end
pellets.each do |name|
if (@pellets.has_key?(name))
@pellets[name].remove(nosave)
else
raise Error::MissingPellet.new(name)
end
end
end
|
#search(regex) ⇒ Object
150
151
152
153
154
155
156
157
|
# File 'lib/mspac.rb', line 150
def search(regex)
@pellets.keys.sort.each do |name|
pellet = @pellets[name]
name_match = pellet.name.match(/#{regex}/)
desc_match = pellet.desc.match(/#{regex}/)
puts pellet.to_s if (name_match || desc_match)
end
end
|
#unlock(pellets) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/mspac.rb', line 159
def unlock(pellets)
if (pellets.nil? || pellets.empty?)
raise Error::MissingPellet.new
end
pellets.each do |name|
if (@pellets.has_key?(name))
@pellets[name].unlock
else
raise Error::MissingPellet.new(name)
end
end
end
|
#upgrade ⇒ Object
173
174
175
176
177
178
|
# File 'lib/mspac.rb', line 173
def upgrade
@pellets.keys.sort.each do |name|
pellet = @pellets[name]
pellet.update if (pellet.installed?)
end
end
|