Class: Transpec::DynamicAnalyzer::RuntimeData
- Inherits:
-
Object
- Object
- Transpec::DynamicAnalyzer::RuntimeData
- Defined in:
- lib/transpec/dynamic_analyzer/runtime_data.rb
Defined Under Namespace
Classes: CompatibleOpenStruct
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #[](node) ⇒ Object
-
#initialize(data = CompatibleOpenStruct.new) ⇒ RuntimeData
constructor
A new instance of RuntimeData.
- #node_id(node) ⇒ Object
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
#data ⇒ Object (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) = { object_class: CompatibleOpenStruct, symbolize_names: true } data = JSON.load(string_or_io, nil, ) 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.(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 |