Class: Transpec::DynamicAnalyzer::RuntimeData

Inherits:
Object
  • Object
show all
Defined in:
lib/transpec/dynamic_analyzer/runtime_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ RuntimeData

Returns a new instance of RuntimeData.



10
11
12
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 10

def initialize(hash = {})
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



8
9
10
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 8

def hash
  @hash
end

Instance Method Details

#[](node) ⇒ Object



14
15
16
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 14

def [](node)
  @hash[node_id(node)]
end

#node_id(node) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 18

def node_id(node)
  source_range = node.loc.expression
  source_buffer = source_range.source_buffer
  absolute_path = File.expand_path(source_buffer.name)
  relative_path = Pathname.new(absolute_path).relative_path_from(Pathname.pwd).to_s
  [relative_path, source_range.begin_pos, source_range.end_pos].join('_')
end