Class: Codebeacon::Tracer::TreeNodeMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/codebeacon/tracer/src/data/tree_node_mapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database) ⇒ TreeNodeMapper

Returns a new instance of TreeNodeMapper.



7
8
9
# File 'lib/codebeacon/tracer/src/data/tree_node_mapper.rb', line 7

def initialize(database)
  @db = database
end

Class Method Details

.create_indexes(database) ⇒ Object



55
56
57
58
59
60
# File 'lib/codebeacon/tracer/src/data/tree_node_mapper.rb', line 55

def self.create_indexes(database)
  database.execute("CREATE INDEX IF NOT EXISTS IDX_treenode_parent_id ON treenodes(parent_id)")
  database.execute("CREATE INDEX IF NOT EXISTS IDX_treenode_node_source_id ON treenodes(node_source_id)")
  database.execute("CREATE INDEX IF NOT EXISTS IDX_treenode_file ON treenodes(file)")
  database.execute("CREATE INDEX IF NOT EXISTS IDX_treenode_called_method ON treenodes(called_method)")
end

.create_table(database) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/codebeacon/tracer/src/data/tree_node_mapper.rb', line 29

def self.create_table(database)
  database.execute <<-SQL
    CREATE TABLE IF NOT EXISTS treenodes (
      id INTEGER PRIMARY KEY,
      file TEXT,
      line INTEGER,
      called_method TEXT,
      method TEXT,
      tp_class TEXT,
      tp_defined_class TEXT,
      tp_class_name TEXT,
      self_type TEXT,
      depth INTEGER,
      caller TEXT,
      gemEntry INTEGER,
      parent_id INTEGER,
      block INTEGER,
      node_source_id INTEGER,
      return_type TEXT,
      return_value TEXT,
      FOREIGN KEY (parent_id) REFERENCES treenodes(id),
      FOREIGN KEY (node_source_id) REFERENCES node_sources(id)
    )
  SQL
end

Instance Method Details

#insert(file, line, called_method, method, tp_class, tp_defined_class, tp_class_name, self_type, depth, caller, gem_entry, parent_id, block, node_source_id, return_type, return_value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/codebeacon/tracer/src/data/tree_node_mapper.rb', line 11

def insert(file, line, called_method, method, tp_class, tp_defined_class, tp_class_name, self_type, depth, caller, gem_entry, parent_id, block, node_source_id, return_type, return_value)
  @db.execute(<<-SQL, 
    INSERT INTO treenodes 
    (
        file, line, called_method, method, tp_class, tp_defined_class, tp_class_name, self_type, depth, caller, 
        gemEntry, parent_id, block, node_source_id, return_type, return_value
    )
    VALUES 
    (
        ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
    )
  SQL
  file, line, called_method, method, tp_class, tp_defined_class, tp_class_name, self_type, depth, caller, 
  gem_entry ? 1 : 0, parent_id, block ? 1 : 0, node_source_id, return_type, return_value)
  
  @db.last_insert_row_id
end