Class: ChaosDetector::ChaosGraphs::ModuleNode

Inherits:
GraphTheory::Node show all
Defined in:
lib/chaos_detector/chaos_graphs/module_node.rb

Overview

Consider putting action/event in this class and naming it accordingly

Constant Summary

Constants inherited from GraphTheory::Node

GraphTheory::Node::ROOT_NODE_NAME

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from GraphTheory::Node

#is_root, #node_origin, #reduction

Instance Method Summary collapse

Methods inherited from GraphTheory::Node

#merge!, #name, #root?

Constructor Details

#initialize(mod_name: nil, mod_path: nil, is_root: false, node_origin: nil, domain_name: nil, mod_type: nil, reduction: nil) ⇒ ModuleNode

Returns a new instance of ModuleNode.



16
17
18
19
20
21
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 16

def initialize(mod_name: nil, mod_path: nil, is_root: false, node_origin: nil, domain_name: nil, mod_type: nil, reduction: nil)
  super(name: mod_name, root: is_root, node_origin: node_origin, reduction: reduction)
  @domain_name = domain_name&.to_s
  @mod_path = mod_path
  @mod_type = mod_type
end

Class Attribute Details

.root_node(force_new: false) ⇒ Object (readonly)

Returns the value of attribute root_node.



78
79
80
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 78

def root_node
  @root_node
end

Instance Attribute Details

#domain_nameObject (readonly)

Returns the value of attribute domain_name.



12
13
14
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 12

def domain_name
  @domain_name
end

#mod_pathObject (readonly)

:unknown, :module, :class



11
12
13
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 11

def mod_path
  @mod_path
end

#mod_typeObject (readonly)

:unknown, :module, :class



10
11
12
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 10

def mod_type
  @mod_type
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
35
36
37
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 32

def ==(other)
  # TODO? Checking domain name vs path name due to mixins/metacoding:
  mod_name == other.mod_name &&
    mod_type == other.mod_type &&
    mod_path == other.mod_path
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 28

def eql?(other)
  self == other
end

#graph_propsObject



47
48
49
50
51
52
53
54
55
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 47

def graph_props
  props = super
  if reduction
    props.merge!(
      cardinality_functions: reduction.reduction_count
    )
  end
  super.merge(props)
end

#hashObject



23
24
25
26
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 23

def hash
  [mod_name, mod_type, mod_path].hash
  # [mod_name, mod_type, domain_name].hash
end

#short_mod_typeObject



57
58
59
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 57

def short_mod_type
  mod_type && "(#{mod_type[0]})"
end

#short_pathObject



61
62
63
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 61

def short_path
  ChaosDetector::Utils::StrUtil.humanize_module(@mod_path, sep_token: '/')
end

#subtitleObject



43
44
45
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 43

def subtitle
  '%s[%s]' % [short_mod_type, domain_name]
end

#titleObject



39
40
41
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 39

def title
  mod_name
end

#to_infoObject



65
66
67
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 65

def to_info
  ChaosDetector::Stacker::ModInfo.new(mod_name: mod_name, mod_path: mod_path, mod_type: mod_type)
end

#to_kObject



69
70
71
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 69

def to_k
  ChaosDetector::Utils::StrUtil.snakeize([domain_name, mod_name, @mod_type, @mod_path].compact.map(&:to_s))
end

#to_sObject



73
74
75
# File 'lib/chaos_detector/chaos_graphs/module_node.rb', line 73

def to_s
  [super, domain_name, @mod_type, short_path].join(', ')
end