Class: ArchUnit::Slices::FluentApi::DiagramSource
- Inherits:
-
Data
- Object
- Data
- ArchUnit::Slices::FluentApi::DiagramSource
- 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
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(kind:, value:) ⇒ DiagramSource
constructor
A new instance of DiagramSource.
- #read ⇒ Object
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
#kind ⇒ Object (readonly)
Returns the value of attribute kind
9 10 11 |
# File 'lib/archunit/slices/fluentapi/diagram_source.rb', line 9 def kind @kind end |
#value ⇒ Object (readonly)
Returns the value of attribute 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
#read ⇒ Object
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 |