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 = []
  @verifications = []
  @operations = []
  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

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#operationsObject

Returns the value of attribute operations.



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

def operations
  @operations
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)
  @operations <<  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)
  @operations << Sprinkle::Installers::BsdPort.new(self, port, &block)
end

#config(&block) ⇒ Object



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

def config(&block)
  @operations << Sprinkle::Installers::Config.new(self, &block)
end

#custom(command, &block) ⇒ Object



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

def custom(command, &block)
  @operations <<  Sprinkle::Installers::Custom.new(self, command, &block)
end

#deb(*names, &block) ⇒ Object



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

def deb(*names, &block)
  @operations <<  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)
  @operations << 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
  @operations <<  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)
  @operations <<  Sprinkle::Installers::MacPort.new(self, port, &block)
end

#openbsd_pkg(*names, &block) ⇒ Object



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

def openbsd_pkg(*names, &block)
  @operations << 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)
  @operations << Sprinkle::Installers::OpensolarisPkg.new(self, *names, &block)
end

#pear(*names, &block) ⇒ Object



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

def pear(*names, &block)
  @operations <<  Sprinkle::Installers::Pear.new(self, *names, &block)
end

#process(deployment, roles) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/sprinkle/package.rb', line 199

def process(deployment, roles)
  return if meta_package?
          
  roles = [roles].flatten
  roles.each do |role|
    servers = deployment.find_servers(role)
    
    servers.each do |server|            
      # 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, server, true)
          logger.info "--> #{self.name} already installed for server: #{server}"
          next
        rescue Sprinkle::VerificationFailed => e
          # Continue
        end
      end

      @operations.each do |installer|
        installer.defaults(deployment) if installer.responds_to?(:defaults)
        installer.process(server)       if installer.responds_to?(:process)
      end
  
      process_verifications(deployment, server)
    end
  end
end

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



229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/sprinkle/package.rb', line 229

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

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



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

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)
  @operations <<  Sprinkle::Installers::Rake.new(self, name, options, &block)        
end

#requires(*packages) ⇒ Object



244
245
246
247
# File 'lib/sprinkle/package.rb', line 244

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)
  @operations <<  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
  @operations <<  Sprinkle::Installers::Source.new(self, source, options, &block)
end

#to_sObject



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

def to_s; @name; end

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



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/sprinkle/package.rb', line 254

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

  @recommends.each do |dep|
    package = PACKAGES[dep]
    next unless package # skip missing recommended packages as they can be optional
    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
end

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



190
191
192
# File 'lib/sprinkle/package.rb', line 190

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)
  @operations <<  Sprinkle::Installers::Yum.new(self, *names, &block)
end