Class: Gamefic::Action
- Inherits:
-
Object
- Object
- Gamefic::Action
- Includes:
- Logging
- Defined in:
- lib/gamefic/action.rb
Overview
The handler for executing responses for a provided actor and array of arguments. It’s also responsible for executing before_action and after_action hooks if necessary.
Defined Under Namespace
Classes: Hook
Instance Attribute Summary collapse
- #actor ⇒ Active readonly
- #arguments ⇒ Array readonly
- #response ⇒ Response readonly
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel an action.
- #cancelled? ⇒ Boolean
- #execute ⇒ Object
-
#executed? ⇒ Boolean
True if the response has been executed.
-
#initialize(actor, arguments, response) ⇒ Action
constructor
A new instance of Action.
- #meta? ⇒ Boolean
- #verb ⇒ Object
Methods included from Logging
Constructor Details
#initialize(actor, arguments, response) ⇒ Action
Returns a new instance of Action.
42 43 44 45 46 |
# File 'lib/gamefic/action.rb', line 42 def initialize actor, arguments, response @actor = actor @arguments = arguments @response = response end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
34 35 36 |
# File 'lib/gamefic/action.rb', line 34 def arguments @arguments end |
#response ⇒ Response (readonly)
37 38 39 |
# File 'lib/gamefic/action.rb', line 37 def response @response end |
Instance Method Details
#cancel ⇒ Object
Cancel an action. This method can be called in an action hook to prevent subsequent hooks and/or the action itself from being executed.
66 67 68 |
# File 'lib/gamefic/action.rb', line 66 def cancel @cancelled = true end |
#cancelled? ⇒ Boolean
70 71 72 |
# File 'lib/gamefic/action.rb', line 70 def cancelled? @cancelled ||= false end |
#execute ⇒ Object
48 49 50 51 52 53 |
# File 'lib/gamefic/action.rb', line 48 def execute return if cancelled? @executed = true response.execute actor, *arguments end |
#executed? ⇒ Boolean
True if the response has been executed. False typically means that the #execute method has not been called or the action was cancelled in a before_action hook.
59 60 61 |
# File 'lib/gamefic/action.rb', line 59 def executed? @executed ||= false end |
#meta? ⇒ Boolean
78 79 80 |
# File 'lib/gamefic/action.rb', line 78 def response. end |
#verb ⇒ Object
74 75 76 |
# File 'lib/gamefic/action.rb', line 74 def verb response.verb end |