Class: Transpec::DynamicAnalyzer::RuntimeData

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

Defined Under Namespace

Classes: CompatibleOpenStruct

Constant Summary

Constants included from Util

Util::LITERAL_TYPES, Util::WHITESPACES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

beginning_of_line_range, block_node_taken_by_method, const_name, contain_here_document?, each_backward_chained_node, each_forward_chained_node, each_line_range, end_of_line_range, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, first_block_arg_name, here_document?, in_explicit_parentheses?, indentation_of_line, line_range, literal?, node_id, proc_literal?, range_from_arg

Constructor Details

#initialize(data = CompatibleOpenStruct.new) ⇒ RuntimeData

Returns a new instance of RuntimeData.



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

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

Class Method Details

.load(string_or_io) ⇒ Object



15
16
17
18
19
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 15

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, key = nil) ⇒ Object



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

def [](node, key = nil)
  node_data = data[node_id(node)]
  return nil unless node_data
  return node_data unless key
  node_data[key]
end

#present?(node, key) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 36

def present?(node, key)
  node_data = self[node]
  return false unless node_data
  node_data.respond_to?(key)
end

#run?(node) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 32

def run?(node)
  !self[node].nil?
end