class Luban::Deployment::Worker::Base

Attributes

task[R]

Public Class Methods

new(config:, backend:, **task, &blk) click to toggle source
# File lib/luban/deployment/worker/base.rb, line 13
def initialize(config:, backend:, **task, &blk)
  @config = config
  @backend = backend
  @run_blk = blk
  @task = create_task(task)
  init
  validate
end

Public Instance Methods

dry_run?() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 23
def dry_run?; task.opts.dry_run; end
force?() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 22
def force?; task.opts.force; end
linux?() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 26
def linux?; os_name == 'Linux'; end
method_missing(sym, *args, &blk) click to toggle source
Calls superclass method
# File lib/luban/deployment/worker/base.rb, line 43
def method_missing(sym, *args, &blk)
  if args.empty? and blk.nil? and config.has_key?(sym)
    singleton_class.send(:define_method, sym) { config.fetch(__method__) }
    send(sym)
  else
    super
  end
end
osx?() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 25
def osx?; os_name == 'Darwin'; end
packages() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 35
def packages; task.opts.packages; end
run() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 37
def run
  with_clean_env do
    update_result(__return__: @run_blk ? run_with_block : run_with_command).to_h
  end
end
target_full_name() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 29
def target_full_name; "#{target_name}-#{target_version}"; end
target_major_version() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 32
def target_major_version; task.opts.major_version || target_version; end
target_name() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 28
def target_name; task.opts.name; end
target_patch_level() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 33
def target_patch_level; task.opts.patch_level || ''; end
target_version() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 31
def target_version; task.opts.version; end

Protected Instance Methods

after_run() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 61
def after_run; end
before_run() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 60
def before_run; end
create_task(task) click to toggle source
# File lib/luban/deployment/worker/base.rb, line 54
def create_task(task)
  Task.new(task).tap { |t| t.result.hostname = hostname }
end
init() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 58
def init; end
run_with_block() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 63
def run_with_block
  before_run
  r = instance_eval &@run_blk
  after_run
  r
end
run_with_command() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 70
def run_with_command
  before_run
  send("before_#{task.cmd}") if respond_to?("before_#{task.cmd}", true)                    
  r = send(task.cmd)
  send("after_#{task.cmd}") if respond_to?("after_#{task.cmd}", true)
  after_run
  r
end
update_result(message = nil, status: :succeeded, level: :info, **attrs) click to toggle source
# File lib/luban/deployment/worker/base.rb, line 79
def update_result(message = nil, status: :succeeded, level: :info, **attrs)
  task.result.tap do |r|
    r.status = status unless status.nil? or !r.status.nil?
    r.level = level unless level.nil? or !r.level.nil?
    r.message = message unless message.nil? or !r.message.nil?
    attrs.each_pair { |k, v| r.send("#{k}=", v) }
    unless message.nil? or message.empty?
      message.split("\n").each { |msg| send(level, msg) }
    end
  end
end
validate() click to toggle source
# File lib/luban/deployment/worker/base.rb, line 59
def validate; end