Class: Baptize::PackageDefinition
- Inherits:
-
Object
- Object
- Baptize::PackageDefinition
- Defined in:
- lib/baptize/package_definition.rb
Instance Attribute Summary collapse
-
#after_block ⇒ Object
readonly
Returns the value of attribute after_block.
-
#before_block ⇒ Object
readonly
Returns the value of attribute before_block.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#description(desc = nil) ⇒ Object
(also: #desc)
readonly
Returns the value of attribute description.
-
#install_block ⇒ Object
readonly
Returns the value of attribute install_block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#verify_block ⇒ Object
readonly
Returns the value of attribute verify_block.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
- #execute(options = {}) ⇒ Object
- #full_name ⇒ Object
-
#initialize(name, execution_scope, registry) ⇒ PackageDefinition
constructor
A new instance of PackageDefinition.
- #install(&block) ⇒ Object
- #method_missing(sym, *args, &block) ⇒ Object
- #requires(*tasks) ⇒ Object
- #respond_to?(sym, include_priv = false) ⇒ Boolean
- #verify(&block) ⇒ Object
Constructor Details
#initialize(name, execution_scope, registry) ⇒ PackageDefinition
Returns a new instance of PackageDefinition.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/baptize/package_definition.rb', line 6 def initialize(name, execution_scope, registry) @name = name @execution_scope = execution_scope @registry = registry @dependencies = [] @install_block = nil @verify_block = nil @before_block = nil @after_block = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/baptize/package_definition.rb', line 74 def method_missing(sym, *args, &block) if @execution_scope.any?(sym) @execution_scope.fetch(sym) elsif @execution_scope.respond_to?(sym) @execution_scope.send(sym, *args, &block) else super end end |
Instance Attribute Details
#after_block ⇒ Object (readonly)
Returns the value of attribute after_block.
4 5 6 |
# File 'lib/baptize/package_definition.rb', line 4 def after_block @after_block end |
#before_block ⇒ Object (readonly)
Returns the value of attribute before_block.
4 5 6 |
# File 'lib/baptize/package_definition.rb', line 4 def before_block @before_block end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
4 5 6 |
# File 'lib/baptize/package_definition.rb', line 4 def dependencies @dependencies end |
#description(desc = nil) ⇒ Object (readonly) Also known as: desc
Returns the value of attribute description.
4 5 6 |
# File 'lib/baptize/package_definition.rb', line 4 def description @description end |
#install_block ⇒ Object (readonly)
Returns the value of attribute install_block.
4 5 6 |
# File 'lib/baptize/package_definition.rb', line 4 def install_block @install_block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/baptize/package_definition.rb', line 4 def name @name end |
#verify_block ⇒ Object (readonly)
Returns the value of attribute verify_block.
4 5 6 |
# File 'lib/baptize/package_definition.rb', line 4 def verify_block @verify_block end |
Instance Method Details
#after(&block) ⇒ Object
104 105 106 |
# File 'lib/baptize/package_definition.rb', line 104 def after(&block) @after_block = block end |
#before(&block) ⇒ Object
100 101 102 |
# File 'lib/baptize/package_definition.rb', line 100 def before(&block) @before_block = block end |
#execute(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/baptize/package_definition.rb', line 17 def execute(={}) unless @registry.packages_executed.include?(full_name) || [:force] @registry.packages_executed << full_name logger.info "Resolving dependencies for #{name}" @registry.before(self).each do |dependency| logger.debug "--> #{dependency}" @registry.resolve_dependency(dependency).tap do |task| task.call end end @dependencies.each do |dependency| logger.debug "--> #{dependency}" @registry.resolve_dependency(dependency).tap do |task| task.call end end instance_eval(&before_block) if self.before_block if verify_block logger.debug "Verifying package #{name}" already_installed = begin instance_eval(&verify_block) true rescue VerificationFailure false end if already_installed && !ENV['FORCE_INSTALL'] logger.info "Skipping previously installed package #{name}" else if already_installed && ENV['FORCE_INSTALL'] logger.important "Force installing previously installed package #{name}" else logger.info "Installing package #{name}" end instance_eval(&install_block) instance_eval(&verify_block) end elsif install_block # logger.important "WARNING: `verify` block not implemented for package #{name}." logger.info "Installing package #{name}" instance_eval(&install_block) else # logger.important "WARNING: `install` block not implemented for package #{name}." logger.info "Nothing to do for package #{name}" end instance_eval(&after_block) if after_block @registry.after(self).each do |dependency| @registry.resolve_dependency(dependency).tap do |task| task.call end end end end |
#full_name ⇒ Object
84 85 86 |
# File 'lib/baptize/package_definition.rb', line 84 def full_name name.to_s end |
#install(&block) ⇒ Object
108 109 110 |
# File 'lib/baptize/package_definition.rb', line 108 def install(&block) @install_block = block end |
#requires(*tasks) ⇒ Object
94 95 96 97 98 |
# File 'lib/baptize/package_definition.rb', line 94 def requires(*tasks) Array(tasks).flatten.each do |name| @dependencies << name end end |
#respond_to?(sym, include_priv = false) ⇒ Boolean
70 71 72 |
# File 'lib/baptize/package_definition.rb', line 70 def respond_to?(sym, include_priv = false) super || @execution_scope.any?(sym) || @execution_scope.respond_to?(sym) end |
#verify(&block) ⇒ Object
112 113 114 |
# File 'lib/baptize/package_definition.rb', line 112 def verify(&block) @verify_block = block end |