Class: Transpec::DynamicAnalyzer::RuntimeData

Inherits:
Object
  • Object
show all
Includes:
NodeUtil
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

Methods included from NodeUtil

#node_id

Constructor Details

#initialize(data = CompatibleOpenStruct.new) ⇒ RuntimeData

Returns a new instance of RuntimeData.



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

def initialize(data = CompatibleOpenStruct.new)
  error_message = data[RUNTIME_DATA_ERROR_MESSAGE_KEY]
  fail AnalysisError, error_message if error_message

  @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
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 15

def self.load(string_or_io)
  data = JSON.load(string_or_io, nil, object_class: CompatibleOpenStruct)
  new(data)
end

Instance Method Details

#[](node, key = nil) ⇒ Object



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

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)


38
39
40
41
42
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 38

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

#run?(node) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/transpec/dynamic_analyzer/runtime_data.rb', line 34

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