Class: Wukong::Runner
- Inherits:
-
Object
- Object
- Wukong::Runner
- Includes:
- Logging, BootSequence, CodeLoader, DeployPackLoader
- Defined in:
- lib/wukong/runner.rb,
lib/wukong/runner/code_loader.rb,
lib/wukong/runner/help_message.rb,
lib/wukong/runner/boot_sequence.rb,
lib/wukong/runner/deploy_pack_loader.rb
Overview
A base class which handles
- requiring any necessary code like deploy packs or code from command-line arguments
- having all plugins configure settings as necessary
- resolving settings
- having all plugins boot from now resolved settings
- parsing command-line arguments
- instantiating and handing over control to a driver which runs the actual code
Direct Known Subclasses
Defined Under Namespace
Modules: BootSequence, CodeLoader, DeployPackLoader, HelpMessage
Instance Attribute Summary collapse
-
#settings ⇒ Object
The settings object that will be configured and booted from.
Class Method Summary collapse
-
.description(msg = nil) ⇒ String
Convenience method for setting the description message of a Runner.
-
.die(message = nil, code = 127) ⇒ Object
Kill this process with the given error
messageand exitcode. -
.run(settings = Configliere::Param.new) ⇒ Object
Instantiates a new Runner and boot it up.
-
.usage(msg = nil) ⇒ String
Convenience method for setting the usage message of a Runner.
Instance Method Summary collapse
-
#args ⇒ Array<String>
The parsed command-line arguments.
-
#dataflow?(name) ⇒ true, false
Is the given
namea registered as a dataflow?. -
#dataflow_class_for(name) ⇒ Wukong::Processor, ...
Retrieve the dataflow registered under a given
name. -
#description ⇒ String
Return the description text for this runner.
-
#initialize(settings = Configliere::Param.new) ⇒ Runner
constructor
Create a new Runner with the given +settings+.
-
#processor?(name) ⇒ true, false
Is the given
namea registered as a processor?. -
#program_name ⇒ String
Return the name of the program this Runner is running.
-
#program_name=(name) ⇒ Object
Explicitly set the name of the program this Runner is running.
-
#registered?(name) ⇒ true, false
Is there a processor or dataflow registered with the given
name?. -
#root ⇒ String
The root directory we should consider ourselves to be running in.
-
#usage ⇒ String
Return the usage message for this runner.
Methods included from BootSequence
Methods included from HelpMessage
#dump_help, #dump_help_and_exit!, #help_given?, #strip_help_param!
Methods included from DeployPackLoader
#deploy_pack_dir, #environment_file, #in_deploy_pack?, #load_deploy_pack, #loaded_deploy_pack?
Methods included from CodeLoader
Methods included from Logging
Constructor Details
#initialize(settings = Configliere::Param.new) ⇒ Runner
Create a new Runner with the given +settings+.
Uses an empty Configliere::Param object if no +settings+ are given.
32 33 34 |
# File 'lib/wukong/runner.rb', line 32 def initialize settings=Configliere::Param.new self.settings = settings end |
Instance Attribute Details
#settings ⇒ Object
The settings object that will be configured and booted from. All plugins will configure this object.
24 25 26 |
# File 'lib/wukong/runner.rb', line 24 def settings @settings end |
Class Method Details
.description(msg = nil) ⇒ String
Convenience method for setting the description message of a Runner.
81 82 83 84 |
# File 'lib/wukong/runner.rb', line 81 def self.description msg=nil return @description unless msg @description = msg end |
.die(message = nil, code = 127) ⇒ Object
Kill this process with the given error message and exit
code.
91 92 93 94 |
# File 'lib/wukong/runner.rb', line 91 def self.die(=nil, code=127) log.error() if exit(code) end |
.run(settings = Configliere::Param.new) ⇒ Object
Instantiates a new Runner and boot it up.
Will rescue any Wukong::Error with a logged error message and exit.
40 41 42 43 44 45 46 |
# File 'lib/wukong/runner.rb', line 40 def self.run(settings=Configliere::Param.new) begin new(settings).boot! rescue Wukong::Error => e die(e., 127) end end |
.usage(msg = nil) ⇒ String
Convenience method for setting the usage message of a Runner.
72 73 74 75 |
# File 'lib/wukong/runner.rb', line 72 def self.usage msg=nil return @usage unless msg @usage = msg end |
Instance Method Details
#args ⇒ Array<String>
The parsed command-line arguments.
Will raise an error if +boot+ hasn't been called yet.
53 54 55 |
# File 'lib/wukong/runner.rb', line 53 def args settings.rest end |
#dataflow?(name) ⇒ true, false
Is the given name a registered as a dataflow?
162 163 164 |
# File 'lib/wukong/runner.rb', line 162 def dataflow?(name) registered?(name) && dataflow_class_for(name).ancestors.include?(Wukong::Dataflow) end |
#dataflow_class_for(name) ⇒ Wukong::Processor, ...
Retrieve the dataflow registered under a given name.
145 146 147 148 |
# File 'lib/wukong/runner.rb', line 145 def dataflow_class_for(name) builder = (Wukong.registry.retrieve(name.to_sym) or return) builder.for_class end |
#description ⇒ String
Return the description text for this runner.
128 129 130 |
# File 'lib/wukong/runner.rb', line 128 def description self.class.description end |
#processor?(name) ⇒ true, false
Is the given name a registered as a processor?
154 155 156 |
# File 'lib/wukong/runner.rb', line 154 def processor?(name) registered?(name) && dataflow_class_for(name).ancestors.include?(Wukong::Processor) end |
#program_name ⇒ String
Return the name of the program this Runner is running.
This is passed to plugins which can configure settings appropriately. Defaults to the name of the currently running process.
103 104 105 |
# File 'lib/wukong/runner.rb', line 103 def program_name @program_name || File.basename($0) end |
#program_name=(name) ⇒ Object
Explicitly set the name of the program this Runner is running.
This is useful for unit tests in which the name of the currently
running process may be different from the runner command being
tested (rspec vs. wu-local).
114 115 116 |
# File 'lib/wukong/runner.rb', line 114 def program_name= name @program_name = name end |
#registered?(name) ⇒ true, false
Is there a processor or dataflow registered with the given
name?
137 138 139 |
# File 'lib/wukong/runner.rb', line 137 def registered? name name && Wukong.registry.registered?(name.to_sym) end |
#root ⇒ String
The root directory we should consider ourselves to be running in.
Defaults to the root directory of a deploy pack if we're running
inside one, else just returns Dir.pwd.
64 65 66 |
# File 'lib/wukong/runner.rb', line 64 def root in_deploy_pack? ? deploy_pack_dir : Dir.pwd end |
#usage ⇒ String
Return the usage message for this runner.
121 122 123 |
# File 'lib/wukong/runner.rb', line 121 def usage ["usage: #{program_name} [ --param=val | --param | -p val | -p ]", self.class.usage].compact.join(' ') end |