Class: Toys::Context
- Inherits:
-
Object
- Object
- Toys::Context
- Defined in:
- lib/toys/context.rb
Instance Attribute Summary collapse
-
#_lookup ⇒ Object
readonly
Returns the value of attribute _lookup.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#binary_name ⇒ Object
readonly
Returns the value of attribute binary_name.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tool_name ⇒ Object
readonly
Returns the value of attribute tool_name.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #_create_child(tool_name, args, options) ⇒ Object
- #exit_with_code(code) ⇒ Object
-
#initialize(lookup, logger: nil, binary_name: nil, tool_name: nil, args: nil, options: nil) ⇒ Context
constructor
A new instance of Context.
- #run(*args) ⇒ Object
Constructor Details
#initialize(lookup, logger: nil, binary_name: nil, tool_name: nil, args: nil, options: nil) ⇒ Context
Returns a new instance of Context.
3 4 5 6 7 8 9 10 |
# File 'lib/toys/context.rb', line 3 def initialize(lookup, logger: nil, binary_name: nil, tool_name: nil, args: nil, options: nil) @_lookup = lookup @logger = logger || Logger.new(STDERR) @binary_name = binary_name @tool_name = tool_name @args = args @options = end |
Instance Attribute Details
#_lookup ⇒ Object (readonly)
Returns the value of attribute _lookup.
32 33 34 |
# File 'lib/toys/context.rb', line 32 def _lookup @_lookup end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
15 16 17 |
# File 'lib/toys/context.rb', line 15 def args @args end |
#binary_name ⇒ Object (readonly)
Returns the value of attribute binary_name.
13 14 15 |
# File 'lib/toys/context.rb', line 13 def binary_name @binary_name end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/toys/context.rb', line 12 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/toys/context.rb', line 16 def @options end |
#tool_name ⇒ Object (readonly)
Returns the value of attribute tool_name.
14 15 16 |
# File 'lib/toys/context.rb', line 14 def tool_name @tool_name end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/toys/context.rb', line 18 def [](key) @options[key] end |
#_create_child(tool_name, args, options) ⇒ Object
34 35 36 37 |
# File 'lib/toys/context.rb', line 34 def _create_child(tool_name, args, ) Context.new(@_lookup, logger: @logger, binary_name: @binary_name, tool_name: tool_name, args: args, options: ) end |
#exit_with_code(code) ⇒ Object
28 29 30 |
# File 'lib/toys/context.rb', line 28 def exit_with_code(code) throw :result, code end |
#run(*args) ⇒ Object
22 23 24 25 26 |
# File 'lib/toys/context.rb', line 22 def run(*args) args = args.flatten tool = @_lookup.lookup(args) tool.execute(self, args.slice(tool.full_name.length..-1)) end |