class SevenBridges::MemoryStoreCSVDumper

Public Class Methods

new(memory_store, base_path) click to toggle source
# File lib/seven_bridges/memory_store_csv_dumper.rb, line 7
def initialize(memory_store, base_path)
  @store = memory_store
  @base_path = base_path
end

Public Instance Methods

dump() click to toggle source
# File lib/seven_bridges/memory_store_csv_dumper.rb, line 12
def dump
  FileUtils.mkdir_p(@base_path)

  CSV.open(nodes_header_file, "wb") do |csv|
    csv << ["path:ID", "name", ":LABEL"]
  end

  CSV.open(nodes_file, "wb") do |csv|
    @store.nodes.each do |node|
      csv << [node[:path], node[:name], ((node[:type] == 'app') ? "METHOD" : "TEST_METHOD")]
    end
  end

  CSV.open(edges_header_file, "wb") do |csv|
    csv << [":START_ID", ":END_ID", ":TYPE"]
  end

  CSV.open(edges_file, "wb") do |csv|
    @store.edges.each do |edge|
      csv << [edge[:from], edge[:to], edge[:label]]
    end
  end
end

Private Instance Methods

edges_file() click to toggle source
# File lib/seven_bridges/memory_store_csv_dumper.rb, line 50
def edges_file
  File.join(@base_path, "#{Process.pid}_relationships.csv")
end
edges_header_file() click to toggle source
# File lib/seven_bridges/memory_store_csv_dumper.rb, line 46
def edges_header_file
  File.join(@base_path, "relationships_header.csv")
end
nodes_file() click to toggle source
# File lib/seven_bridges/memory_store_csv_dumper.rb, line 42
def nodes_file
  File.join(@base_path, "#{Process.pid}_nodes.csv")
end
nodes_header_file() click to toggle source
# File lib/seven_bridges/memory_store_csv_dumper.rb, line 38
def nodes_header_file
  File.join(@base_path, "nodes_header.csv")
end