Class: DRbQS::Setting::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Misc
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

Constant Summary

Constants included from Misc

Misc::STRINGS_FOR_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Misc

create_logger, create_uri, output_error, process_running_normally?, random_key, time_to_history_string, time_to_history_string2, uri_drbunix

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.



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

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.



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

def source
  @source
end

Instance Method Details

#cloneObject



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

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'.



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

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

#string_for_shellObject



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

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

#valueObject



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

def value
  @source.value
end