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 ⇒ self
-
#executed? ⇒ Boolean
True if the response has been executed.
-
#initialize(actor, arguments, response) ⇒ Action
constructor
A new instance of Action.
- #meta? ⇒ Boolean
- #narrative ⇒ Object
- #verb ⇒ Object
Methods included from Logging
Constructor Details
#initialize(actor, arguments, response) ⇒ Action
Returns a new instance of Action.
44 45 46 47 48 |
# File 'lib/gamefic/action.rb', line 44 def initialize actor, arguments, response @actor = actor @arguments = arguments @response = response end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
36 37 38 |
# File 'lib/gamefic/action.rb', line 36 def arguments @arguments end |
#response ⇒ Response (readonly)
39 40 41 |
# File 'lib/gamefic/action.rb', line 39 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.
71 72 73 |
# File 'lib/gamefic/action.rb', line 71 def cancel @cancelled = true end |
#cancelled? ⇒ Boolean
75 76 77 |
# File 'lib/gamefic/action.rb', line 75 def cancelled? @cancelled ||= false end |
#execute ⇒ self
51 52 53 54 55 56 57 58 |
# File 'lib/gamefic/action.rb', line 51 def execute return self if cancelled? || executed? Gamefic.logger.info "Executing #{([verb] + [arguments]).flatten.map(&:inspect).join(', ')}" @executed = true response.execute actor, *arguments self 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.
64 65 66 |
# File 'lib/gamefic/action.rb', line 64 def executed? @executed ||= false end |
#meta? ⇒ Boolean
87 88 89 |
# File 'lib/gamefic/action.rb', line 87 def response. end |
#narrative ⇒ Object
83 84 85 |
# File 'lib/gamefic/action.rb', line 83 def narrative response.narrative end |
#verb ⇒ Object
79 80 81 |
# File 'lib/gamefic/action.rb', line 79 def verb response.verb end |