Module: Trailblazer::Activity::Introspect
- Defined in:
- lib/trailblazer/activity/introspect.rb,
lib/trailblazer/activity/introspect/render.rb
Overview
The Introspect API provides inflections for ‘Activity` instances.
It abstracts internals about circuits and provides a convenient API to third-parties such as tracing, rendering an activity, or finding particular tasks.
Defined Under Namespace
Class Method Summary collapse
- .find_path(activity, segments) ⇒ Object
-
.Graph(*args) ⇒ Object
TODO: remove with 0.1.0.
-
.Nodes(activity, task: nil, **options) ⇒ Object
Public entry point for Trailblazer::Activity instance introspection.
- .render_task(proc) ⇒ Object
Class Method Details
.find_path(activity, segments) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/trailblazer/activity/introspect.rb', line 28 def self.find_path(activity, segments) raise ArgumentError.new(%([Trailblazer] Please pass #{activity}.to_h[:activity] into #find_path.)) unless activity.is_a?(Trailblazer::Activity) segments = [nil, *segments] attributes = nil last_activity = nil activity = TaskWrap.container_activity_for(activity) # needed for empty/root path segments.each do |segment| attributes = Introspect.Nodes(activity, id: segment) or return nil last_activity = activity activity = attributes.task end return attributes, last_activity end |
.Graph(*args) ⇒ Object
TODO: remove with 0.1.0.
61 62 63 64 65 |
# File 'lib/trailblazer/activity/introspect.rb', line 61 def self.Graph(*args) Deprecate.warn caller_locations[0], %(`Trailblazer::Activity::Introspect::Graph` is deprecated. Please use `Trailblazer::Developer::Introspect.Graph`) Trailblazer::Developer::Introspect::Graph.new(*args) end |
.Nodes(activity, task: nil, **options) ⇒ Object
Public entry point for Trailblazer::Activity instance introspection.
9 10 11 12 13 14 15 16 |
# File 'lib/trailblazer/activity/introspect.rb', line 9 def self.Nodes(activity, task: nil, **) schema = activity.to_h nodes = schema[:nodes] return Nodes.find_by_id(nodes, [:id]) if .key?(:id) return nodes.fetch(task) if task nodes end |
.render_task(proc) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/trailblazer/activity/introspect.rb', line 46 def self.render_task(proc) if proc.is_a?(Method) receiver = proc.receiver receiver = receiver.is_a?(Class) ? (receiver.name || "#<Class:0x>") : (receiver.name || "#<Module:0x>") # "#<Class:0x>" return "#<Method: #{receiver}.#{proc.name}>" elsif proc.is_a?(Symbol) return proc.to_s end proc.inspect end |