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_block, attributes) ⇒ BasicSource

Returns a new instance of BasicSource.



371
372
373
374
# File 'lib/asciidoctor-diagram/extensions.rb', line 371

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



369
370
371
# File 'lib/asciidoctor-diagram/extensions.rb', line 369

def attributes
  @attributes
end

Instance Method Details

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



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/asciidoctor-diagram/extensions.rb', line 380

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

  value = @attributes[name]

  if value.nil? && inherit
    case inherit
      when String
        value = @parent_block.attr("#{inherit}-#{name}", default_value, true)
      else
        value = @parent_block.attr(name, default_value, true)
    end
  end

  value || default_value
end

#checksumObject



405
406
407
# File 'lib/asciidoctor-diagram/extensions.rb', line 405

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

#create_image_metadataObject



401
402
403
# File 'lib/asciidoctor-diagram/extensions.rb', line 401

def 
  {'checksum' => checksum}
end

#image_nameObject



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

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

#should_process?(image_file, image_metadata) ⇒ Boolean

Returns:

  • (Boolean)


397
398
399
# File 'lib/asciidoctor-diagram/extensions.rb', line 397

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