Class: Luban::Deployment::Worker::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers::Configuration, Helpers::Utils, Parameters::Application, Parameters::General, Parameters::Project
Defined in:
lib/luban/deployment/worker/base.rb

Constant Summary

Constants included from Parameters::Application

Parameters::Application::DefaultLogrotateInterval, Parameters::Application::DefaultLogrotateMaxAge

Constants included from Parameters::General

Parameters::General::DefaultLubanRootPath

Constants included from Helpers::Utils

Helpers::Utils::LogLevels

Instance Attribute Summary collapse

Attributes included from Helpers::Utils

#backend

Attributes included from Helpers::Configuration

#config

Instance Method Summary collapse

Methods included from Parameters::Application

#env_name, #logrotate_count, #monitor_itself?, #monitorable?

Methods included from Parameters::Base

#parameter

Methods included from Parameters::Project

#monitor_defined?, #process_monitor_via

Methods included from Parameters::General

included

Methods included from Helpers::Utils

#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cp, #directory?, #exists?, #file?, #hardware_name, #host, #hostname, #ln, #match?, #md5_for, #md5_for_dir, #md5_for_file, #md5_matched?, #mkdir, #mv, #now, #os_name, #os_release, #readlink, #render_template, #revision_match?, #rm, #rmdir, #sudo, #symlink?, #touch, #truncate, #upload_by_template, #url_exists?, #user_home

Methods included from Helpers::Configuration

#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?

Constructor Details

#initialize(config:, backend:, **task, &blk) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &blk) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/luban/deployment/worker/base.rb', line 41

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

Instance Attribute Details

#taskObject (readonly)

Returns the value of attribute task.



11
12
13
# File 'lib/luban/deployment/worker/base.rb', line 11

def task
  @task
end

Instance Method Details

#dry_run?Boolean

Returns:

  • (Boolean)


23
# File 'lib/luban/deployment/worker/base.rb', line 23

def dry_run?; task.opts.dry_run; end

#force?Boolean

Returns:

  • (Boolean)


22
# File 'lib/luban/deployment/worker/base.rb', line 22

def force?; task.opts.force; end

#linux?Boolean

Returns:

  • (Boolean)


26
# File 'lib/luban/deployment/worker/base.rb', line 26

def linux?; os_name == 'Linux'; end

#osx?Boolean

Returns:

  • (Boolean)


25
# File 'lib/luban/deployment/worker/base.rb', line 25

def osx?; os_name == 'Darwin'; end

#packagesObject



35
# File 'lib/luban/deployment/worker/base.rb', line 35

def packages; task.opts.packages; end

#runObject



37
38
39
# File 'lib/luban/deployment/worker/base.rb', line 37

def run
  update_result(__return__: @run_blk ? run_with_block : run_with_command).to_h
end

#target_full_nameObject



29
# File 'lib/luban/deployment/worker/base.rb', line 29

def target_full_name; "#{target_name}-#{target_version}"; end

#target_major_versionObject



32
# File 'lib/luban/deployment/worker/base.rb', line 32

def target_major_version; task.opts.major_version || target_version; end

#target_nameObject



28
# File 'lib/luban/deployment/worker/base.rb', line 28

def target_name; task.opts.name; end

#target_patch_levelObject



33
# File 'lib/luban/deployment/worker/base.rb', line 33

def target_patch_level; task.opts.patch_level || ''; end

#target_versionObject



31
# File 'lib/luban/deployment/worker/base.rb', line 31

def target_version; task.opts.version; end