Class: Excavator::Environment
- Inherits:
-
Object
- Object
- Excavator::Environment
- Defined in:
- lib/excavator/environment.rb
Overview
Public: Environment instances are created for a Command’s block to execute in. It is designed for modification and manipulation. Adding other methods into this class will allow all Commands to reference them.
Examples
module Helpers
def pretty_logger(msg)
puts "*~*~*~*"
puts msg
puts "*~*~*~*"
end
end
# Add Helpers to Environment
Excavator::Environment.modify Helpers
param :msg
command :print do
# #pretty_logger is now available
pretty_logger params[:msg]
end
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#raw_params ⇒ Object
readonly
Returns the value of attribute raw_params.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
-
#unparsed_params ⇒ Object
readonly
Returns the value of attribute unparsed_params.
Class Method Summary collapse
-
.modify(*mods, &block) ⇒ Object
Public: A convenience method to include other modules in this class.
Instance Method Summary collapse
-
#execute(command, params = {}) ⇒ Object
Public: Execute another command.
-
#initialize(options = {}) ⇒ Environment
constructor
A new instance of Environment.
Constructor Details
#initialize(options = {}) ⇒ Environment
Returns a new instance of Environment.
38 39 40 41 42 43 |
# File 'lib/excavator/environment.rb', line 38 def initialize( = {}) @runner = [:runner] @params = [:params] @raw_params = [:raw_params] @unparsed_params = [:unparsed_params] end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
36 37 38 |
# File 'lib/excavator/environment.rb', line 36 def params @params end |
#raw_params ⇒ Object (readonly)
Returns the value of attribute raw_params.
36 37 38 |
# File 'lib/excavator/environment.rb', line 36 def raw_params @raw_params end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
36 37 38 |
# File 'lib/excavator/environment.rb', line 36 def runner @runner end |
#unparsed_params ⇒ Object (readonly)
Returns the value of attribute unparsed_params.
36 37 38 |
# File 'lib/excavator/environment.rb', line 36 def unparsed_params @unparsed_params end |
Class Method Details
.modify(*mods, &block) ⇒ Object
Public: A convenience method to include other modules in this class.
31 32 33 34 |
# File 'lib/excavator/environment.rb', line 31 def self.modify(*mods, &block) mods.each { |m| include m } instance_eval &block if block end |
Instance Method Details
#execute(command, params = {}) ⇒ Object
Public: Execute another command. This is a convenience method to execute other commands defined in Excavator. #execute will return the value of the executed command (useful for building reusable blocks of code).
command - A String full name of a command. This should include namespaces. params - A Hash of Param name to values to pass to this command.
Examples
namespace :test do
command :prepare do
puts params[:foo]
# => "bar"
end
command :run do
execute "test:prepare", {:foo => "bar"}
end
end
Returns value from executed command.
66 67 68 69 |
# File 'lib/excavator/environment.rb', line 66 def execute(command, params = {}) command = runner.find_command(command) command.execute(params) end |