Class: Makwa::Interaction
- Inherits:
-
ActiveInteraction::Base
- Object
- ActiveInteraction::Base
- Makwa::Interaction
- Defined in:
- lib/makwa/interaction.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Interrupt
Instance Method Summary collapse
-
#calling_interaction ⇒ String
The backtrace entry for the immediately calling interaction (first item in calling_interactions).
-
#calling_interactions ⇒ Array<String>
The callstack containing interactions only, starting with the immediate caller.
-
#debug(txt) ⇒ Object
The standard method for all logging output.
-
#id_marker ⇒ String
A marker that identifies an interaction instance by its Ruby object_id.
-
#indent ⇒ String
A prefix that indents each debug line according to the level of interactions nesting.
-
#return_if_errors! ⇒ Object
Exits early if there are any errors.
Instance Method Details
#calling_interaction ⇒ String
Returns 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_interactions ⇒ Array<String>
Returns 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_marker ⇒ String
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.
73 74 75 |
# File 'lib/makwa/interaction.rb', line 73 def id_marker "(id##{object_id})" end |
#indent ⇒ String
Returns 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.
22 23 24 |
# File 'lib/makwa/interaction.rb', line 22 def return_if_errors! raise(Interrupt, ActiveInteraction::Errors.new(self)) if errors_any? end |