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



112
113
114
115
116
117
118
119
120
121
# 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 = []
  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



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

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

#deb(*names, &block) ⇒ Object



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

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

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



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

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

#process(deployment, roles) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/sprinkle/package.rb', line 157

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



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/sprinkle/package.rb', line 179

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

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



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

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

#requires(*packages) ⇒ Object



194
195
196
197
# File 'lib/sprinkle/package.rb', line 194

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

#rpm(*names, &block) ⇒ Object



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

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

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



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

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

#to_sObject



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

def to_s; @name; end

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



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/sprinkle/package.rb', line 204

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]
    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



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

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

#yum(*names, &block) ⇒ Object



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

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