Class: Yacl::Define::Cli::Runner
- Inherits:
-
Object
- Object
- Yacl::Define::Cli::Runner
- Defined in:
- lib/yacl/define/cli/runner.rb
Overview
Public: The Runner class is to be used by app developers as the entry point for the commandline programs. A class that inherits from Runner is what is placed in a bin/myapp file in the project structure.
The Runner is configured with the Plan to use for loading the configuratin properties and when the plan is loaded, the properties are available via the #properties method.
Example:
class MyApp::Runner < Yacl::Define::Cli::Runner
plan MyApp::Plan
def run
puts properties.database.server
end
end
And in your ‘bin/myapp-cli’ file you would have:
# automatically populate with ARGV and ENV
MyApp::Runner.go
# or be explicit
MyApp::Runner.go( ARGV, ENV )
Direct Known Subclasses
Defined Under Namespace
Classes: Error
Class Method Summary collapse
-
.go(argv = ARGV, env = ENV) ⇒ Object
Public: Execute the Runner.
-
.plan(*args) ⇒ Object
Public: Define the Plan associated with this Runner.
Instance Method Summary collapse
-
#initialize(argv = ARGV, env = ENV) ⇒ Runner
constructor
Internal: Initalize the Runner.
-
#plan_klass ⇒ Object
Internal: return the Plan class defined for this Runner class.
-
#properties ⇒ Object
Public: Access the Properties instance that is created by the Plan.
Constructor Details
#initialize(argv = ARGV, env = ENV) ⇒ Runner
Internal: Initalize the Runner.
argv - The commandline args to use (default: ARGV) env - The enviroment hash to use (default: ENV )
This method should be avoided by end users, they should call #go instead.
60 61 62 63 |
# File 'lib/yacl/define/cli/runner.rb', line 60 def initialize( argv = ARGV, env = ENV ) raise Error, "No plan class specified in #{self.class}" unless self.class.plan @plan = plan_klass.new( :argv => argv, :env => env ) end |
Class Method Details
.go(argv = ARGV, env = ENV) ⇒ Object
Public: Execute the Runner
argv - The commandline args to use (default: ARGV) env - The enviroment hash to use (default: ENV )
It is assumed that when this method exits, the program is over.
Returns nothing.
39 40 41 42 |
# File 'lib/yacl/define/cli/runner.rb', line 39 def self.go( argv = ARGV, env = ENV ) r = self.new( argv, env ) r.run end |
.plan(*args) ⇒ Object
Public: Define the Plan associated with this Runner.
plan - A class you define that inherits from Yacl::Define::Plan
Returns: the plan class if it is set, nil otherwise.
49 50 51 52 |
# File 'lib/yacl/define/cli/runner.rb', line 49 def self.plan( *args ) @plan_klass = args.first unless args.empty? return @plan_klass end |
Instance Method Details
#plan_klass ⇒ Object
Internal: return the Plan class defined for this Runner class
Returns a Plan class
77 78 79 |
# File 'lib/yacl/define/cli/runner.rb', line 77 def plan_klass self.class.plan end |
#properties ⇒ Object
Public: Access the Properties instance that is created by the Plan. This is the fully realized Properties of the plan and should be considered read-only.
Returns a Properties instance.
70 71 72 |
# File 'lib/yacl/define/cli/runner.rb', line 70 def properties @plan.properties end |