Class: Vagabund::Settler::Projects::Base
- Inherits:
-
Object
- Object
- Vagabund::Settler::Projects::Base
- Defined in:
- lib/vagabund/settler/projects/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #action_exec(command, machine) ⇒ Object
- #configure(&block) ⇒ Object
- #exec_after(action, machine) ⇒ Object
- #exec_before(action, machine) ⇒ Object
- #hook_exec(hook, action, machine) ⇒ Object
- #name ⇒ Object
- #project_path ⇒ Object
- #provision(machine) ⇒ Object
- #pull(machine) ⇒ Object
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/vagabund/settler/projects/base.rb', line 7 def config @config end |
Instance Method Details
#action_exec(command, machine) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vagabund/settler/projects/base.rb', line 47 def action_exec(command, machine) self.class.instance_eval do [:ask, :detail, :error, :info, :output, :warn].each do |cmd| define_method cmd do |*args, &block| machine.ui.send cmd, *args, &block end end [:execute, :sudo, :test].each do |cmd| define_method cmd do |*args, &block| opts = {verbose: false}.merge(args.) if opts[:verbose] == true machine.communicate.send cmd, *args, opts do |type,data| color = type == :stderr ? :red : :green = { color: color, new_line: false, prefix: false } detail(data, ) block.call(type, data) unless block.nil? end else machine.communicate.send cmd, *args, opts, &block end end end define_method :capture do |*args, &block| output = '' machine.communicate.execute *args do |type,data| output += data if type == :stdout block.call(type, data) unless block.nil? end output end end instance_exec self, machine, machine.communicate, &command if command.is_a?(Proc) self.class.instance_eval do [:ask, :detail, :error, :info, :output, :warn, :capture, :execute, :sudo, :test].each do |cmd| undef_method cmd end end end |
#configure(&block) ⇒ Object
94 95 96 |
# File 'lib/vagabund/settler/projects/base.rb', line 94 def configure(&block) config.configure &block end |
#exec_after(action, machine) ⇒ Object
31 32 33 |
# File 'lib/vagabund/settler/projects/base.rb', line 31 def exec_after(action, machine) hook_exec :after, action, machine end |
#exec_before(action, machine) ⇒ Object
27 28 29 |
# File 'lib/vagabund/settler/projects/base.rb', line 27 def exec_before(action, machine) hook_exec :before, action, machine end |
#hook_exec(hook, action, machine) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vagabund/settler/projects/base.rb', line 35 def hook_exec(hook, action, machine) hook_action = "#{hook.to_s}_#{action.to_s.gsub(/[eo]r$/, '')}" return if config.send(hook_action).nil? || config.send(hook_action).empty? machine.ui.detail "Executing custom :#{hook_action} hooks for project #{name}..." config.send(hook_action).each do |hact| action_exec hact, machine end rescue StandardError => e raise Settler::Errors::ProjectError, e end |
#name ⇒ Object
98 99 100 |
# File 'lib/vagabund/settler/projects/base.rb', line 98 def name config.name end |
#project_path ⇒ Object
102 103 104 |
# File 'lib/vagabund/settler/projects/base.rb', line 102 def project_path config.project_path end |
#provision(machine) ⇒ Object
9 10 11 12 13 |
# File 'lib/vagabund/settler/projects/base.rb', line 9 def provision(machine) exec_before :project, machine pull machine exec_after :project, machine end |
#pull(machine) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vagabund/settler/projects/base.rb', line 15 def pull(machine) exec_before :pull, machine if config.puller.nil? config.source.pull machine, project_path else action_exec config.puller, machine end exec_after :pull, machine rescue StandardError => e raise Settler::Errors::ProjectError, e end |