Class: Sprinkle::Package::Package

Inherits:
Object
  • Object
show all
Includes:
ArbitraryOptions
Defined in:
lib/sprinkle/package.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ArbitraryOptions

included, #method_missing_with_arbitrary_options

Constructor Details

#initialize(name, metadata = {}, &block) ⇒ Package

Returns a new instance of Package.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/sprinkle/package.rb', line 112

def initialize(name,  = {}, &block)
  raise 'No package name supplied' unless name

  @name = name
  @provides = [:provides]
  @dependencies = []
  @recommends = []
  @optional = []
  @verifications = []
  self.instance_eval &block
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



110
111
112
# File 'lib/sprinkle/package.rb', line 110

def dependencies
  @dependencies
end

#installerObject

Returns the value of attribute installer.



110
111
112
# File 'lib/sprinkle/package.rb', line 110

def installer
  @installer
end

#nameObject

Returns the value of attribute name.



110
111
112
# File 'lib/sprinkle/package.rb', line 110

def name
  @name
end

#providesObject

Returns the value of attribute provides.



110
111
112
# File 'lib/sprinkle/package.rb', line 110

def provides
  @provides
end

#recommends(*packages) ⇒ Object

Returns the value of attribute recommends.



110
111
112
# File 'lib/sprinkle/package.rb', line 110

def recommends
  @recommends
end

#verificationsObject

Returns the value of attribute verifications.



110
111
112
# File 'lib/sprinkle/package.rb', line 110

def verifications
  @verifications
end

Instance Method Details

#apt(*names, &block) ⇒ Object



144
145
146
# File 'lib/sprinkle/package.rb', line 144

def apt(*names, &block)
  @installer = Sprinkle::Installers::Apt.new(self, *names, &block)
end

#bsd_port(port, &block) ⇒ Object



136
137
138
# File 'lib/sprinkle/package.rb', line 136

def bsd_port(port, &block)
  @installer = Sprinkle::Installers::BsdPort.new(self, port, &block)
end

#deb(*names, &block) ⇒ Object



148
149
150
# File 'lib/sprinkle/package.rb', line 148

def deb(*names, &block)
  @installer = Sprinkle::Installers::Deb.new(self, *names, &block)
end

#freebsd_pkg(*names, &block) ⇒ Object



124
125
126
# File 'lib/sprinkle/package.rb', line 124

def freebsd_pkg(*names, &block)
  @installer = Sprinkle::Installers::FreebsdPkg.new(self, *names, &block)
end

#gem(name, options = {}, &block) ⇒ Object



160
161
162
163
# File 'lib/sprinkle/package.rb', line 160

def gem(name, options = {}, &block)
  @recommends << :rubygems
  @installer = Sprinkle::Installers::Gem.new(self, name, options, &block)
end

#mac_port(port, &block) ⇒ Object



140
141
142
# File 'lib/sprinkle/package.rb', line 140

def mac_port(port, &block)
  @installer = Sprinkle::Installers::MacPort.new(self, port, &block)
end

#noop(&block) ⇒ Object



174
175
176
# File 'lib/sprinkle/package.rb', line 174

def noop(&block)
  @installer = Sprinkle::Installers::Noop.new(self, name, options, &block)        
end

#openbsd_pkg(*names, &block) ⇒ Object



128
129
130
# File 'lib/sprinkle/package.rb', line 128

def openbsd_pkg(*names, &block)
  @installer = Sprinkle::Installers::OpenbsdPkg.new(self, *names, &block)
end

#opensolaris_pkg(*names, &block) ⇒ Object



132
133
134
# File 'lib/sprinkle/package.rb', line 132

def opensolaris_pkg(*names, &block)
  @installer = Sprinkle::Installers::OpensolarisPkg.new(self, *names, &block)
end

#optional(*packages) ⇒ Object



237
238
239
240
# File 'lib/sprinkle/package.rb', line 237

def optional(*packages)
  @optional << packages
  @optional.flatten!
end

#process(deployment, roles) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/sprinkle/package.rb', line 190

def process(deployment, roles)
  return if meta_package?
  
  # Run a pre-test to see if the software is already installed. If so,
  # we can skip it, unless we have the force option turned on!
  unless @verifications.empty? || Sprinkle::OPTIONS[:force]
    begin
      process_verifications(deployment, roles, true)
      
      logger.info "--> #{self.name} already installed for roles: #{roles}"
      return
    rescue Sprinkle::VerificationFailed => e
      # Continue
    end
  end

  @installer.defaults(deployment)
  @installer.process(roles)
  
  process_verifications(deployment, roles)
end

#process_verifications(deployment, roles, pre = false) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/sprinkle/package.rb', line 212

def process_verifications(deployment, roles, pre = false)
  return if @verifications.blank?
  
  if pre
    logger.info "--> Checking if #{self.name} is already installed for roles: #{roles}"
  else
    logger.info "--> Verifying #{self.name} was properly installed for roles: #{roles}"
  end
  
  @verifications.each do |v|
    v.defaults(deployment)
    v.process(roles)
  end
end

#push_text(text, path, options = {}, &block) ⇒ Object



178
179
180
# File 'lib/sprinkle/package.rb', line 178

def push_text(text, path, options = {}, &block)
  @installer = Sprinkle::Installers::PushText.new(self, text, path, options, &block)
end

#rake(name, options = {}, &block) ⇒ Object



170
171
172
# File 'lib/sprinkle/package.rb', line 170

def rake(name, options = {}, &block)
  @installer = Sprinkle::Installers::Rake.new(self, name, options, &block)        
end

#requires(*packages) ⇒ Object



227
228
229
230
# File 'lib/sprinkle/package.rb', line 227

def requires(*packages)
  @dependencies << packages
  @dependencies.flatten!
end

#rpm(*names, &block) ⇒ Object



152
153
154
# File 'lib/sprinkle/package.rb', line 152

def rpm(*names, &block)
  @installer = Sprinkle::Installers::Rpm.new(self, *names, &block)
end

#source(source, options = {}, &block) ⇒ Object



165
166
167
168
# File 'lib/sprinkle/package.rb', line 165

def source(source, options = {}, &block)
  @recommends << :build_essential # Ubuntu/Debian
  @installer = Sprinkle::Installers::Source.new(self, source, options, &block)
end

#to_sObject



273
# File 'lib/sprinkle/package.rb', line 273

def to_s; @name; end

#transfer(source, destination, options = {}, &block) ⇒ Object



182
183
184
# File 'lib/sprinkle/package.rb', line 182

def transfer(source, destination, options = {}, &block)
				@installer = Sprinkle::Installers::Transfer.new(self, source, destination, options, &block)
end

#tree(depth = 1, &block) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/sprinkle/package.rb', line 242

def tree(depth = 1, &block)
  packages = []

  @recommends.each do |dep|
    package = PACKAGES[dep]
    next unless package # skip missing recommended packages as they're allowed to not exist
    block.call(self, package, depth) if block
    packages << package.tree(depth + 1, &block)
  end

  @dependencies.each do |dep|
    package = PACKAGES[dep]
    package = select_package(dep, package) if package.is_a? Array
    
    raise "Package definition not found for key: #{dep}" unless package
    block.call(self, package, depth) if block
    packages << package.tree(depth + 1, &block)
  end

  packages << self

  @optional.each do |dep|
    package = PACKAGES[dep]
    next unless package # skip missing optional packages as they're allow to not exist
    block.call(self, package, depth) if block
    packages << package.tree(depth + 1, &block)
  end

  packages
end

#verify(description = '', &block) ⇒ Object



186
187
188
# File 'lib/sprinkle/package.rb', line 186

def verify(description = '', &block)
  @verifications << Sprinkle::Verify.new(self, description, &block)
end

#yum(*names, &block) ⇒ Object



156
157
158
# File 'lib/sprinkle/package.rb', line 156

def yum(*names, &block)
  @installer = Sprinkle::Installers::Yum.new(self, *names, &block)
end