Class: DRbQS::Setting::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/drbqs/setting/base.rb

Overview

A base class having options of commands. We must define a method 'exec' this method in a child class.

Direct Known Subclasses

Execute, Manage, Node, SSH, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ Base

The keys of options are

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :all_keys_defined (Boolean)

    Check existences of keys on setting values.

  • :log_level (Boolean)

    Use the option of log level.

  • :daemon (Boolean)

    Use the option of daemon.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/drbqs/setting/base.rb', line 21

def initialize(opts = {}, &block)
  @source = DRbQS::Setting::Source.new(opts[:all_keys_defined])
  @source.register_key(:debug, :bool => true)
  if opts[:log_level]
    @source.register_key(:log_level, :check => 1, :default => [Logger::ERROR])
  end
  if opts[:daemon]
    @__daemon__ = nil
    @source.register_key(:daemon, :check => 1)
  end
  @source.instance_eval(&block) if block_given?
  @options = {}
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



15
16
17
# File 'lib/drbqs/setting/base.rb', line 15

def source
  @source
end

Instance Method Details

#cloneObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/drbqs/setting/base.rb', line 53

def clone
  new_obj = self.class.new
  instance_variables.each do |var_name|
    var = instance_variable_get(var_name)
    case var
    when NilClass, FalseClass, TrueClass, Symbol
      new_var = var
    else
      new_var = var.clone
    end
    new_obj.instance_variable_set(var_name, new_var)
  end
  new_obj
end

#parse!Object

We execute DRbQS::Setting::Base#parse! before execute 'exec'.



73
74
75
76
77
78
79
# File 'lib/drbqs/setting/base.rb', line 73

def parse!
  preprocess!
  @source.check!
  $DEBUG = true if get_first(:debug)
  @__daemon__ = get_first(:daemon)
  parse_log_level
end

#string_for_shellObject



45
46
47
# File 'lib/drbqs/setting/base.rb', line 45

def string_for_shell
  command_line_argument(true).join(" ")
end

#valueObject



49
50
51
# File 'lib/drbqs/setting/base.rb', line 49

def value
  @source.value
end