class Asciidoctor::Diagram::Extensions::BasicSource

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.

Attributes

attributes[R]

Public Class Methods

new(parent_block, attributes) click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 410
def initialize(parent_block, attributes)
  @parent_block = parent_block
  @attributes = attributes
end

Public Instance Methods

attr(name, default_value=nil, inherit=nil) click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 419
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, Symbol
        value = @parent_block.attr("#{inherit.to_s}-#{name}", default_value, true)
      else
        value = @parent_block.attr(name, default_value, true)
    end
  end

  value || default_value
end
checksum() click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 444
def checksum
  @checksum ||= compute_checksum(code)
end
create_image_metadata() click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 440
def create_image_metadata
  {'checksum' => checksum}
end
image_name() click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 415
def image_name
  attr('target', 'diag-' + checksum)
end
should_process?(image_file, image_metadata) click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 436
def should_process?(image_file, image_metadata)
  image_metadata['checksum'] != checksum
end

Protected Instance Methods

resolve_diagram_subs() click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 449
def resolve_diagram_subs
  if @attributes.key? 'subs'
    @parent_block.resolve_block_subs @attributes['subs'], nil, 'diagram'
  else
    []
  end
end

Private Instance Methods

compute_checksum(code) click to toggle source
# File lib/asciidoctor-diagram/extensions.rb, line 458
def compute_checksum(code)
  md5 = Digest::MD5.new
  md5 << code
  @attributes.each do |k, v|
    md5 << k.to_s if k
    md5 << v.to_s if v
  end
  md5.hexdigest
end