Class: Asciidoctor::Diagram::Extensions::BasicSource

Inherits:
Object
  • Object
show all
Includes:
DiagramSource
Defined in:
lib/asciidoctor-diagram/extensions.rb

Overview

Base class for diagram source implementations that uses an md5 checksum of the source code of a diagram to determine if it has been updated or not.

Direct Known Subclasses

FileSource, ReaderSource

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DiagramSource

#base_dir, #code, #to_s

Constructor Details

#initialize(parent, attributes) ⇒ BasicSource

Returns a new instance of BasicSource.



357
358
359
360
# File 'lib/asciidoctor-diagram/extensions.rb', line 357

def initialize(parent, attributes)
  @parent = parent
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



355
356
357
# File 'lib/asciidoctor-diagram/extensions.rb', line 355

def attributes
  @attributes
end

Instance Method Details

#attr(name, default_value = nil, inherit = nil) ⇒ Object



366
367
368
369
370
371
372
373
374
# File 'lib/asciidoctor-diagram/extensions.rb', line 366

def attr(name, default_value=nil, inherit=nil)
  name = name.to_s if ::Symbol === name

  if inherit
    @attributes[name] || @parent.attr(name, default_value, true)
  else
    @attributes[name] || default_value
  end
end

#checksumObject



384
385
386
# File 'lib/asciidoctor-diagram/extensions.rb', line 384

def checksum
  @checksum ||= compute_checksum(code)
end

#create_image_metadataObject



380
381
382
# File 'lib/asciidoctor-diagram/extensions.rb', line 380

def 
  {'checksum' => checksum}
end

#image_nameObject



362
363
364
# File 'lib/asciidoctor-diagram/extensions.rb', line 362

def image_name
  attr('target', 'diag-' + checksum)
end

#should_process?(image_file, image_metadata) ⇒ Boolean

Returns:

  • (Boolean)


376
377
378
# File 'lib/asciidoctor-diagram/extensions.rb', line 376

def should_process?(image_file, )
  ['checksum'] != checksum
end