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



62
63
64
# File 'lib/makwa/interaction.rb', line 62

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
57
58
59
# 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") \
      && !e.index("`debug'")
  }
end

#debug(txt) ⇒ Object

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



67
68
69
# File 'lib/makwa/interaction.rb', line 67

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.



73
74
75
# File 'lib/makwa/interaction.rb', line 73

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.



78
79
80
81
# File 'lib/makwa/interaction.rb', line 78

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, ActiveInteraction::Errors.new(self)) if errors_any?
end