module SevenBridges

Constants

VERSION

Attributes

klass[W]
project_root[W]
store[W]

Public Class Methods

add_calling_relationship(current) click to toggle source
# File lib/seven_bridges.rb, line 69
def add_calling_relationship(current)
  return if @callstack.empty?

  SevenBridges.store.add_relationship(:calls, @callstack.last[:node], current)
  SevenBridges.store.add_relationship(:called_by, current, @callstack.first[:node])
end
after_setup() click to toggle source
# File lib/seven_bridges.rb, line 31
def after_setup
  @callstack = []
  @trace = TracePoint.new(:call) do |tp|
    if tp.path.start_with? SevenBridges.project_root
      path = make_path(tp)
      if !path.end_with?('#teardown')
        find_location_and_build_graph path
      end
    end
  end
  @trace.enable
end
before_teardown() click to toggle source
# File lib/seven_bridges.rb, line 82
def before_teardown
  @trace.disable
  @callstack = []
end
configure() { |self| ... } click to toggle source
# File lib/seven_bridges.rb, line 27
def configure
  yield self

  klass.class_eval do
    def after_setup
      @callstack = []
      @trace = TracePoint.new(:call) do |tp|
        if tp.path.start_with? SevenBridges.project_root
          path = make_path(tp)
          if !path.end_with?('#teardown')
            find_location_and_build_graph path
          end
        end
      end
      @trace.enable
    end

    private

    def make_path(tp)
      "#{strip_project_root(tp.path)}##{tp.method_id}"
    end

    def get_or_create_current_node(path)
      current = SevenBridges.store.find_method(path)
      return current if current.present?

      return SevenBridges.store.create_test_method_node(get_method_name(path), path) if @callstack.empty?
      return SevenBridges.store.create_method_node(get_method_name(path), path)
    end

    def find_location_and_build_graph(path)
      find_parent
      current = get_or_create_current_node(path)
      add_calling_relationship current
      create_stack_frame current
    end

    def create_stack_frame(current)
      @callstack << { node: current, level: caller.size }
    end

    def add_calling_relationship(current)
      return if @callstack.empty?

      SevenBridges.store.add_relationship(:calls, @callstack.last[:node], current)
      SevenBridges.store.add_relationship(:called_by, current, @callstack.first[:node])
    end

    def find_parent
      while(!@callstack.empty? && caller.size <= @callstack.last[:level]) do
        @callstack.pop
      end
    end

    def before_teardown
      @trace.disable
      @callstack = []
    end

    def get_method_name(path)
      path.split('#')[1]
    end

    def strip_project_root(path)
      path[SevenBridges.project_root.length..-1]
    end
  end
end
create_stack_frame(current) click to toggle source
# File lib/seven_bridges.rb, line 65
def create_stack_frame(current)
  @callstack << { node: current, level: caller.size }
end
find_location_and_build_graph(path) click to toggle source
# File lib/seven_bridges.rb, line 58
def find_location_and_build_graph(path)
  find_parent
  current = get_or_create_current_node(path)
  add_calling_relationship current
  create_stack_frame current
end
find_parent() click to toggle source
# File lib/seven_bridges.rb, line 76
def find_parent
  while(!@callstack.empty? && caller.size <= @callstack.last[:level]) do
    @callstack.pop
  end
end
get_method_name(path) click to toggle source
# File lib/seven_bridges.rb, line 87
def get_method_name(path)
  path.split('#')[1]
end
get_or_create_current_node(path) click to toggle source
# File lib/seven_bridges.rb, line 50
def get_or_create_current_node(path)
  current = SevenBridges.store.find_method(path)
  return current if current.present?

  return SevenBridges.store.create_test_method_node(get_method_name(path), path) if @callstack.empty?
  return SevenBridges.store.create_method_node(get_method_name(path), path)
end
klass() click to toggle source
# File lib/seven_bridges.rb, line 15
def klass
  @klass ||= Minitest::Test
end
make_path(tp) click to toggle source
# File lib/seven_bridges.rb, line 46
def make_path(tp)
  "#{strip_project_root(tp.path)}##{tp.method_id}"
end
project_root() click to toggle source
# File lib/seven_bridges.rb, line 19
def project_root
  @project_root ||= ''
end
store() click to toggle source
# File lib/seven_bridges.rb, line 23
def store
  @store ||= SevenBridges::Neo4jStore.new
end
strip_project_root(path) click to toggle source
# File lib/seven_bridges.rb, line 91
def strip_project_root(path)
  path[SevenBridges.project_root.length..-1]
end