Class: ArchUnit::Common::Extraction::Graph

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/archunit/common/extraction/graph.rb

Overview

An immutable, enumerable list of dependency edges.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(edges = []) ⇒ Graph

Returns a new instance of Graph.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
# File 'lib/archunit/common/extraction/graph.rb', line 14

def initialize(edges = [])
  @edges = Array(edges).dup
  invalid_edges = @edges.grep_v(Edge)
  raise ArgumentError, 'graph accepts only Edge values' unless invalid_edges.empty?

  validate_identifier_style
  @edges.freeze
  freeze
end

Instance Attribute Details

#edgesObject (readonly)

Returns the value of attribute edges.



12
13
14
# File 'lib/archunit/common/extraction/graph.rb', line 12

def edges
  @edges
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



45
46
47
# File 'lib/archunit/common/extraction/graph.rb', line 45

def ==(other)
  other.is_a?(Graph) && edges == other.edges
end

#[]Object



28
29
30
# File 'lib/archunit/common/extraction/graph.rb', line 28

def [](*)
  edges[*]
end

#eachObject



24
25
26
# File 'lib/archunit/common/extraction/graph.rb', line 24

def each(&)
  edges.each(&)
end

#empty?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/archunit/common/extraction/graph.rb', line 37

def empty?
  edges.empty?
end

#hashObject



50
51
52
# File 'lib/archunit/common/extraction/graph.rb', line 50

def hash
  [self.class, edges].hash
end

#sizeObject Also known as: length



32
33
34
# File 'lib/archunit/common/extraction/graph.rb', line 32

def size
  edges.size
end

#to_aObject



41
42
43
# File 'lib/archunit/common/extraction/graph.rb', line 41

def to_a
  edges.dup
end