Class: Gamefic::Action

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Logging

logger

Constructor Details

#initialize(actor, arguments, response) ⇒ Action

Returns a new instance of Action.

Parameters:



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

#actorActive (readonly)

Returns:



31
32
33
# File 'lib/gamefic/action.rb', line 31

def actor
  @actor
end

#argumentsArray (readonly)

Returns:



34
35
36
# File 'lib/gamefic/action.rb', line 34

def arguments
  @arguments
end

#responseResponse (readonly)

Returns:



37
38
39
# File 'lib/gamefic/action.rb', line 37

def response
  @response
end

Instance Method Details

#cancelObject

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

Returns:

  • (Boolean)


70
71
72
# File 'lib/gamefic/action.rb', line 70

def cancelled?
  @cancelled ||= false
end

#executeObject



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.

Returns:

  • (Boolean)


59
60
61
# File 'lib/gamefic/action.rb', line 59

def executed?
  @executed ||= false
end

#meta?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/gamefic/action.rb', line 78

def meta?
  response.meta?
end

#verbObject



74
75
76
# File 'lib/gamefic/action.rb', line 74

def verb
  response.verb
end