Class: ArchUnit::Slices::FluentApi::DiagramSource

Inherits:
Data
  • Object
show all
Defined in:
lib/archunit/slices/fluentapi/diagram_source.rb

Overview

Immutable inline or file-backed PlantUML source, read only by a terminal check.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, value:) ⇒ DiagramSource

Returns a new instance of DiagramSource.



19
20
21
22
23
24
25
26
27
28
# File 'lib/archunit/slices/fluentapi/diagram_source.rb', line 19

def initialize(kind:, value:)
  unless DIAGRAM_SOURCE_KINDS.include?(kind)
    raise ArgumentError, "kind must be one of: #{DIAGRAM_SOURCE_KINDS.join(', ')}"
  end
  unless value.is_a?(String) && !value.empty?
    raise ArgumentError, 'diagram source value must be a non-empty String'
  end

  super(kind:, value: value.dup.freeze)
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



9
10
11
# File 'lib/archunit/slices/fluentapi/diagram_source.rb', line 9

def kind
  @kind
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



9
10
11
# File 'lib/archunit/slices/fluentapi/diagram_source.rb', line 9

def value
  @value
end

Class Method Details

.file(path) ⇒ Object



14
15
16
17
# File 'lib/archunit/slices/fluentapi/diagram_source.rb', line 14

def self.file(path)
  path = path.to_path if path.respond_to?(:to_path)
  new(kind: :file, value: path)
end

.inline(text) ⇒ Object



10
11
12
# File 'lib/archunit/slices/fluentapi/diagram_source.rb', line 10

def self.inline(text)
  new(kind: :inline, value: text)
end

Instance Method Details

#readObject



30
31
32
# File 'lib/archunit/slices/fluentapi/diagram_source.rb', line 30

def read
  kind == :inline ? value : File.read(value, encoding: Encoding::UTF_8)
end