Class: Wukong::Runner
- Inherits:
-
Object
- Object
- Wukong::Runner
- Includes:
- Logging, BootSequence, CodeLoader, CommandRunner, 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/command_runner.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, CommandRunner, 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
message
and 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
name
a 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
name
a 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.
34 35 36 |
# File 'lib/wukong/runner.rb', line 34 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.
26 27 28 |
# File 'lib/wukong/runner.rb', line 26 def settings @settings end |
Class Method Details
.description(msg = nil) ⇒ String
Convenience method for setting the description message of a Runner.
83 84 85 86 |
# File 'lib/wukong/runner.rb', line 83 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
.
93 94 95 96 |
# File 'lib/wukong/runner.rb', line 93 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.
42 43 44 45 46 47 48 |
# File 'lib/wukong/runner.rb', line 42 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.
74 75 76 77 |
# File 'lib/wukong/runner.rb', line 74 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.
55 56 57 |
# File 'lib/wukong/runner.rb', line 55 def args settings.rest end |
#dataflow?(name) ⇒ true, false
Is the given name
a registered as a dataflow?
164 165 166 |
# File 'lib/wukong/runner.rb', line 164 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
.
147 148 149 150 |
# File 'lib/wukong/runner.rb', line 147 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.
130 131 132 |
# File 'lib/wukong/runner.rb', line 130 def description self.class.description end |
#processor?(name) ⇒ true, false
Is the given name
a registered as a processor?
156 157 158 |
# File 'lib/wukong/runner.rb', line 156 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.
105 106 107 |
# File 'lib/wukong/runner.rb', line 105 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
).
116 117 118 |
# File 'lib/wukong/runner.rb', line 116 def program_name= name @program_name = name end |
#registered?(name) ⇒ true, false
Is there a processor or dataflow registered with the given
name
?
139 140 141 |
# File 'lib/wukong/runner.rb', line 139 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
.
66 67 68 |
# File 'lib/wukong/runner.rb', line 66 def root in_deploy_pack? ? deploy_pack_dir : Dir.pwd end |
#usage ⇒ String
Return the usage message for this runner.
123 124 125 |
# File 'lib/wukong/runner.rb', line 123 def usage ["usage: #{program_name} [ --param=val | --param | -p val | -p ]", self.class.usage].compact.join(' ') end |