Class: Prepper::Package
- Inherits:
-
Object
- Object
- Prepper::Package
- Includes:
- Tools::Apt, Tools::File, Tools::Rbenv, Tools::Text, Tools::Users, SSHKit::DSL
- Defined in:
- lib/prepper/package.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#name ⇒ Object
Returns the value of attribute name.
-
#runner ⇒ Object
Returns the value of attribute runner.
-
#verifications ⇒ Object
Returns the value of attribute verifications.
Instance Method Summary collapse
- #add_command(command, opts = {}) ⇒ Object
- #execute_command(command) ⇒ Object
-
#initialize(name, opts = {}, &block) ⇒ Package
constructor
A new instance of Package.
- #process ⇒ Object
- #run_command(method, command) ⇒ Object
- #should_run? ⇒ Boolean
- #test_command(command) ⇒ Object
- #verify(&block) ⇒ Object
Methods included from Tools::Rbenv
Methods included from Tools::Text
Methods included from Tools::File
#chown, #directory, #file, #has_directory?, #has_file?, #has_symlink?, #matches_content?, #render_template, #symlink
Methods included from Tools::Users
Methods included from Tools::Apt
#apt_install, #apt_update, #has_apt_package?
Constructor Details
#initialize(name, opts = {}, &block) ⇒ Package
Returns a new instance of Package.
12 13 14 15 16 17 18 19 |
# File 'lib/prepper/package.rb', line 12 def initialize(name, opts = {}, &block) @name = name @opts = opts @runner = opts[:runner] @verifications = [] @commands = [] instance_eval &block if block_given? end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
10 11 12 |
# File 'lib/prepper/package.rb', line 10 def commands @commands end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/prepper/package.rb', line 10 def name @name end |
#runner ⇒ Object
Returns the value of attribute runner.
10 11 12 |
# File 'lib/prepper/package.rb', line 10 def runner @runner end |
#verifications ⇒ Object
Returns the value of attribute verifications.
10 11 12 |
# File 'lib/prepper/package.rb', line 10 def verifications @verifications end |
Instance Method Details
#add_command(command, opts = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/prepper/package.rb', line 50 def add_command(command, opts = {}) opts[:user] ||= "root" opts[:within] ||= "/" @commands << Command.new(command, opts) end |
#execute_command(command) ⇒ Object
56 57 58 |
# File 'lib/prepper/package.rb', line 56 def execute_command(command) run_command(:execute, command) end |
#process ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/prepper/package.rb', line 32 def process unless should_run? SSHKit.config.output.write(SSHKit::LogMessage.new(1, "Skipping package #{name}")) return end @commands.each do |command| if command.verifier if !test_command(command.verifier) execute_command(command) else SSHKit.config.output.write(SSHKit::LogMessage.new(1, "Skipping command #{command.to_s}")) end else execute_command(command) end end end |
#run_command(method, command) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/prepper/package.rb', line 64 def run_command(method, command) on [runner.server_hash], in: :sequence do |host| within command.within do as command.user do with command.env do if respond_to? command.to_s.to_sym send command.to_s.to_sym, *command.opts[:params] else if method == :execute execute command.to_s else send(method, command.to_s) end end end end end end end |
#should_run? ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/prepper/package.rb', line 21 def should_run? return true if @verifications.empty? return @verifications.all? do |verification| !test_command(verification.call) end end |
#test_command(command) ⇒ Object
60 61 62 |
# File 'lib/prepper/package.rb', line 60 def test_command(command) run_command(:test, command) end |
#verify(&block) ⇒ Object
28 29 30 |
# File 'lib/prepper/package.rb', line 28 def verify(&block) @verifications << block end |