class Gamefic::Action
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.
Attributes
actor[R]
@return [Active]
arguments[R]
@return [Array]
response[R]
@return [Response]
Public Class Methods
new(actor, arguments, response)
click to toggle source
@param actor [Active] @param arguments [Array] @param response [Response]
# File lib/gamefic/action.rb, line 44 def initialize actor, arguments, response @actor = actor @arguments = arguments @response = response end
Public Instance Methods
cancel()
click to toggle source
Cancel an action. This method can be called in an action hook to prevent subsequent hooks and/or the action itself from being executed.
# File lib/gamefic/action.rb, line 71 def cancel @cancelled = true end
cancelled?()
click to toggle source
# File lib/gamefic/action.rb, line 75 def cancelled? @cancelled ||= false end
execute()
click to toggle source
@return [self]
# 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?()
click to toggle source
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.
# File lib/gamefic/action.rb, line 64 def executed? @executed ||= false end
meta?()
click to toggle source
# File lib/gamefic/action.rb, line 87 def meta? response.meta? end
narrative()
click to toggle source
# File lib/gamefic/action.rb, line 83 def narrative response.narrative end
verb()
click to toggle source
# File lib/gamefic/action.rb, line 79 def verb response.verb end