Class: Transpec::DynamicAnalyzer::RuntimeData

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

Defined Under Namespace

Classes: CompatibleOpenStruct

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = CompatibleOpenStruct.new) ⇒ RuntimeData

Returns a new instance of RuntimeData.



18
19
20
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 18

def initialize(data = CompatibleOpenStruct.new)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

Class Method Details

.load(string_or_io) ⇒ Object



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

def self.load(string_or_io)
  options = { object_class: CompatibleOpenStruct, symbolize_names: true }
  data = JSON.load(string_or_io, nil, options)
  new(data)
end

Instance Method Details

#[](node) ⇒ Object



22
23
24
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 22

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

#node_id(node) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 26

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