Class: Cogy::Context
- Inherits:
-
Object
- Object
- Cogy::Context
- Defined in:
- lib/cogy/context.rb
Overview
Context represents a particular invocation request of a Command performed by a user. It holds state like the given arguments, options etc. In other words, it provides the context in which a Command should be invoked.
A Context essentially is an HTTP request performed by ‘cogy:cogy` (github.com/skroutz/cogy-bundle) on behalf of the user. You can think of it as the equivalent of the ActionPack’s ‘Request` object.
Instance Attribute Summary collapse
- #args ⇒ Array readonly
- #command ⇒ Command readonly
- #env ⇒ Hash readonly
- #handle ⇒ String readonly
- #opts ⇒ Hash readonly
Instance Method Summary collapse
-
#initialize(command, args, opts, handle, env) ⇒ Context
constructor
A new instance of Context.
-
#invoke ⇒ Object
Invokes the command pointed by #command.
Constructor Details
#initialize(command, args, opts, handle, env) ⇒ Context
Note:
By ‘user’ we refer to the user who invoked the command in chat.
Returns a new instance of Context.
37 38 39 40 41 42 43 44 45 |
# File 'lib/cogy/context.rb', line 37 def initialize(command, args, opts, handle, env) @command = command @args = args @opts = opts @handle = handle @env = env define_arg_helpers end |
Instance Attribute Details
#args ⇒ Array (readonly)
15 16 17 |
# File 'lib/cogy/context.rb', line 15 def args @args end |
#command ⇒ Command (readonly)
12 13 14 |
# File 'lib/cogy/context.rb', line 12 def command @command end |
#env ⇒ Hash (readonly)
24 25 26 |
# File 'lib/cogy/context.rb', line 24 def env @env end |
#handle ⇒ String (readonly)
21 22 23 |
# File 'lib/cogy/context.rb', line 21 def handle @handle end |
#opts ⇒ Hash (readonly)
18 19 20 |
# File 'lib/cogy/context.rb', line 18 def opts @opts end |
Instance Method Details
#invoke ⇒ Object
Invokes the command pointed by #command.
52 53 54 |
# File 'lib/cogy/context.rb', line 52 def invoke instance_eval(&command.handler) end |