Class: DRbQS::Setting::Base
- Inherits:
-
Object
- Object
- DRbQS::Setting::Base
- 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.
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #clone ⇒ Object
-
#initialize(opts = {}, &block) ⇒ Base
constructor
The keys of options are.
-
#parse! ⇒ Object
We execute DRbQS::Setting::Base#parse! before execute 'exec'.
- #string_for_shell ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(opts = {}, &block) ⇒ Base
The keys of options are
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
#source ⇒ Object (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
#clone ⇒ Object
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_shell ⇒ Object
45 46 47 |
# File 'lib/drbqs/setting/base.rb', line 45 def string_for_shell command_line_argument(true).join(" ") end |
#value ⇒ Object
49 50 51 |
# File 'lib/drbqs/setting/base.rb', line 49 def value @source.value end |