Class: Terraspace::Dependency::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/terraspace/dependency/node.rb

Constant Summary collapse

@@nodes =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Node

Returns a new instance of Node.



5
6
7
8
# File 'lib/terraspace/dependency/node.rb', line 5

def initialize(name)
  @name = name
  @children, @parents = Set.new, Set.new
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/terraspace/dependency/node.rb', line 4

def children
  @children
end

#filteredObject

Returns the value of attribute filtered.



4
5
6
# File 'lib/terraspace/dependency/node.rb', line 4

def filtered
  @filtered
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/terraspace/dependency/node.rb', line 3

def name
  @name
end

#parentsObject

Returns the value of attribute parents.



4
5
6
# File 'lib/terraspace/dependency/node.rb', line 4

def parents
  @parents
end

Class Method Details

.find_by(name:) ⇒ Object



33
34
35
# File 'lib/terraspace/dependency/node.rb', line 33

def find_by(name:)
  @@nodes.find { |n| n.name == name }
end

.find_or_create_by(name:) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/terraspace/dependency/node.rb', line 25

def find_or_create_by(name:)
  node = find_by(name: name)
  return node if node
  node = Node.new(name)
  @@nodes << node
  node
end

Instance Method Details

#highlighted?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/terraspace/dependency/node.rb', line 10

def highlighted?
  @filtered
end

#inspectObject



14
15
16
# File 'lib/terraspace/dependency/node.rb', line 14

def inspect
  @name
end

#parent!(parent) ⇒ Object



18
19
20
21
# File 'lib/terraspace/dependency/node.rb', line 18

def parent!(parent)
  @parents << parent
  parent.children << self
end