Class: Cogy::Context
- Inherits:
-
Object
- Object
- Cogy::Context
- Defined in:
- lib/cogy/context.rb,
lib/cogy/invocation.rb
Overview
Context represents a particular invocation request of a Command performed by a user. It holds state like the command 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 the ‘cogy:cogy` command (github.com/skroutz/cogy-bundle) on behalf of the user. You can think of it as the equivalent of the ActionPack’s ‘Request` class.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
The Cog command arguments as provided by the user who invoked the command.
-
#env ⇒ Object
readonly
The Cogy environment (ie. all environment variables in the Relay executable that start with ‘COGY_’).
-
#handle ⇒ String
readonly
The chat handle of the user who invoked the command.
-
#opts ⇒ Object
readonly
The Cog command options as provided by the user who invoked the command.
-
#user ⇒ Object
readonly
The chat handle of the user who invoked the command.
Instance Method Summary collapse
-
#initialize(args, opts, user, env) ⇒ Context
constructor
A new instance of Context.
-
#run!(cmd) ⇒ String
Executes a Command in the context of self.
Constructor Details
#initialize(args, opts, user, env) ⇒ Context
Returns a new instance of Context.
34 35 36 37 38 39 |
# File 'lib/cogy/context.rb', line 34 def initialize(args, opts, handle, env) @args = args @opts = opts @handle = handle @env = env end |
Instance Attribute Details
#args ⇒ Object (readonly)
The Cog command arguments as provided by the user who invoked the command.
15 16 17 |
# File 'lib/cogy/context.rb', line 15 def args @args end |
#env ⇒ Object (readonly)
The Cogy environment (ie. all environment variables in the Relay executable that start with ‘COGY_’)
32 33 34 |
# File 'lib/cogy/context.rb', line 32 def env @env end |
#handle ⇒ String (readonly)
Returns The chat handle of the user who invoked the command.
26 27 28 |
# File 'lib/cogy/context.rb', line 26 def handle @handle end |
#opts ⇒ Object (readonly)
The Cog command options as provided by the user who invoked the command
21 22 23 |
# File 'lib/cogy/context.rb', line 21 def opts @opts end |
#user ⇒ Object (readonly)
The chat handle of the user who invoked the command
24 25 26 |
# File 'lib/cogy/invocation.rb', line 24 def user @user end |
Instance Method Details
#run!(cmd) ⇒ String
Executes a Cogy::Command in the context of self.
48 49 50 |
# File 'lib/cogy/context.rb', line 48 def run!(cmd) instance_eval(&cmd.handler) end |