Class: Makwa::Interaction

Inherits:
ActiveInteraction::Base
  • Object
show all
Defined in:
lib/makwa/interaction.rb

Direct Known Subclasses

ReturningInteraction

Defined Under Namespace

Classes: Interrupt

Instance Method Summary collapse

Instance Method Details

#calling_interactionString

Returns the backtrace entry for the immediately calling interaction (first item in calling_interactions).

Returns:

  • (String)

    the backtrace entry for the immediately calling interaction (first item in calling_interactions).



59
60
61
# File 'lib/makwa/interaction.rb', line 59

def calling_interaction
  @calling_interaction ||= calling_interactions.first&.split("/interactions/")&.last || ""
end

#calling_interactionsArray<String>

Returns the callstack containing interactions only, starting with the immediate caller.

Returns:

  • (Array<String>)

    the callstack containing interactions only, starting with the immediate caller.



52
53
54
55
56
# File 'lib/makwa/interaction.rb', line 52

def calling_interactions
  @calling_interactions ||= caller.find_all { |e|
    e.index("/app/interactions/") && !e.index(__FILE__) && !e.index("/returning_interaction.rb")
  }
end

#debug(txt) ⇒ Object

The standard method for all logging output. Turn this on for detailed interaction logging.



64
65
66
# File 'lib/makwa/interaction.rb', line 64

def debug(txt)
  # puts indent + txt
end

#id_markerString

Returns a marker that identifies an interaction instance by its Ruby object_id. This is helpful when following an execution log with nested or interleaved interaction log lines.

Returns:

  • (String)

    a marker that identifies an interaction instance by its Ruby object_id. This is helpful when following an execution log with nested or interleaved interaction log lines.



70
71
72
# File 'lib/makwa/interaction.rb', line 70

def id_marker
  "(id##{object_id})"
end

#indentString

Returns a prefix that indents each debug line according to the level of interactions nesting.

Returns:

  • (String)

    a prefix that indents each debug line according to the level of interactions nesting.



75
76
77
78
# File 'lib/makwa/interaction.rb', line 75

def indent
  lvl = [0, calling_interactions.count].max
  "  " * lvl
end

#return_if_errors!Object

Exits early if there are any errors.

Raises:



22
23
24
# File 'lib/makwa/interaction.rb', line 22

def return_if_errors!
  raise(Interrupt, errors) if errors_any?
end