Class: Pot::Verify
- Inherits:
-
Object
- Object
- Pot::Verify
- Defined in:
- lib/pot/verify.rb
Overview
Verification Methods
As documented in Pot::Package, you may define a block on a package which verifies that a package was installed correctly. If this verification block fails, Pot will stop the script gracefully, raising the error.
In addition to checking post install if it was successfully, verification blocks are also run before an install to see if a package is already installed. If this is the case, the package is skipped and Pot continues with the next package. This behavior can be overriden by setting the -f flag on the Pot script or setting Pot.config.force to true if you’re using Pot programmatically.
An Example
The following verifies that rails was installed correctly be checking to see if the ‘rails’ command is available on the command line:
package :rails do
gem 'rails'
verify do
has_executable 'rails'
end
end
Available Verifiers
There are a variety of available methods for use in the verification block. The standard methods are defined in the Pot::Verifiers module, so see their corresponding documentation.
Custom Verifiers
If you feel that the built-in verifiers do not offer a certain aspect of verification which you need, you may create your own verifier! Simply wrap any method in a module which you want to use:
module MagicBeansVerifier
def has_magic_beans(sauce)
@commands << '[ -z "`echo $' + sauce + '`"]'
end
end
The method can append as many commands as it wishes to the @commands array. These commands will be run on the remote server and MUST give an exit status of 0 if successful or other if unsuccessful.
To register your verifier, call the register method on Pot::Verify:
Sprinle::Verify.register(MagicBeansVerifier)
And now you may use it like any other verifier:
package :magic_beans do
gem 'magic_beans'
verify { has_magic_beans('ranch') }
end
Instance Attribute Summary collapse
-
#commands ⇒ Object
include Pot::Configurable.
-
#description ⇒ Object
include Pot::Configurable.
-
#package ⇒ Object
include Pot::Configurable.
Class Method Summary collapse
-
.register(new_module) ⇒ Object
Register a verification module.
Instance Method Summary collapse
-
#initialize(package, description = '', &block) ⇒ Verify
constructor
:nodoc:.
-
#process(actor, pre = false) ⇒ Object
:nodoc:.
Constructor Details
#initialize(package, description = '', &block) ⇒ Verify
:nodoc:
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pot/verify.rb', line 72 def initialize(package, description = '', &block) #:nodoc: raise 'Verify requires a block.' unless block @package = package @description = description @commands = [] @options ||= {} @options[:padding] = 4 self.instance_eval(&block) end |
Instance Attribute Details
#commands ⇒ Object
include Pot::Configurable
63 64 65 |
# File 'lib/pot/verify.rb', line 63 def commands @commands end |
#description ⇒ Object
include Pot::Configurable
63 64 65 |
# File 'lib/pot/verify.rb', line 63 def description @description end |
#package ⇒ Object
include Pot::Configurable
63 64 65 |
# File 'lib/pot/verify.rb', line 63 def package @package end |
Class Method Details
.register(new_module) ⇒ Object
Register a verification module
67 68 69 |
# File 'lib/pot/verify.rb', line 67 def register(new_module) class_eval { include new_module } end |
Instance Method Details
#process(actor, pre = false) ⇒ Object
:nodoc:
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pot/verify.rb', line 84 def process(actor, pre = false) #:nodoc: description = @description.empty? ? @package.name : @description if Pot.logger.debug? Pot.logger.debug "#{@package.name}#{description} verification sequence: #{@commands.join('; ')}\n" end unless Pot.config.testing? Pot.logger.info "#{" " * @options[:padding]}--> Verifying #{description}..." unless actor.verify(self) # Verification failed, halt sprinkling gracefully. raise Pot::VerificationFailed.new(@package, description) end end end |