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:



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

#actorActive (readonly)

Returns:



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

def actor
  @actor
end

#argumentsArray (readonly)

Returns:



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

def arguments
  @arguments
end

#responseResponse (readonly)

Returns:



39
40
41
# File 'lib/gamefic/action.rb', line 39

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.



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

def cancel
  @cancelled = true
end

#cancelled?Boolean

Returns:

  • (Boolean)


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

def cancelled?
  @cancelled ||= false
end

#executeself

Returns:

  • (self)


51
52
53
54
55
56
57
# File 'lib/gamefic/action.rb', line 51

def execute
  return self if cancelled? || executed?

  @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.

Returns:

  • (Boolean)


63
64
65
# File 'lib/gamefic/action.rb', line 63

def executed?
  @executed ||= false
end

#meta?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/gamefic/action.rb', line 86

def meta?
  response.meta?
end

#narrativeObject



82
83
84
# File 'lib/gamefic/action.rb', line 82

def narrative
  response.narrative
end

#verbObject



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

def verb
  response.verb
end