Module: Duxml::History

Includes:
Duxml, Reportable
Included in:
HistoryClass
Defined in:
lib/duxml/meta/history.rb,
lib/duxml/meta/history.rb

Overview

monitors XML Elements for changes and GrammarClass for errors, recording them and saving to Meta file

Constant Summary

Constants included from Duxml

DITA_GRAMMAR

Constants included from Meta

Meta::FILE_EXT

Instance Attribute Summary

Attributes included from Duxml

#doc, #file, #meta

Attributes included from Saxer

#io

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reportable

#add_observer

Methods included from Duxml

#create, #load, #log, #relaxng, #save, #validate

Methods included from Meta

#grammar=, meta_path

Methods included from Saxer

#sax

Class Method Details

.xmlElement

used when creating a new metadata file for a static XML file

Returns:

  • (Element)

    XML element for a new <duxml:history> node



44
45
46
# File 'lib/duxml/meta/history.rb', line 44

def self.xml
  Element.new(name.nmtokenize).extend self
end

Instance Method Details

#descriptionString

Returns entire history, calling #description on each event in chronological order

Returns:

  • (String)

    returns entire history, calling #description on each event in chronological order



70
71
72
73
74
75
# File 'lib/duxml/meta/history.rb', line 70

def description
  "history follows: \n" +
  events.reverse.collect do |change_or_error|
    change_or_error.description
  end.join("\n")
end

#grammarGrammarClass

Returns grammar that is observing this history’s events.

Returns:

  • (GrammarClass)

    grammar that is observing this history’s events



60
61
62
# File 'lib/duxml/meta/history.rb', line 60

def grammar
  @observer_peers.first.first if @observer_peers and @observer_peers.any? and @observer_peers.first.any?
end

#inspectString

Returns shortened self description for debugging.

Returns:

  • (String)

    shortened self description for debugging



65
66
67
# File 'lib/duxml/meta/history.rb', line 65

def inspect
  "#<#{self.class.to_s} #{object_id}: @events=#{nodes.size}>"
end

#latestChangeClass, ErrorClass

Returns the latest event.

Returns:



55
56
57
# File 'lib/duxml/meta/history.rb', line 55

def latest
  events[0]
end

#strict?(harsh_or_kind = nil) ⇒ Boolean

Returns toggles (true by default) whether History will raise exception or tolerate qualify errors.

Returns:

  • (Boolean)

    toggles (true by default) whether History will raise exception or tolerate qualify errors



49
50
51
52
# File 'lib/duxml/meta/history.rb', line 49

def strict?(harsh_or_kind=nil)
  @strict = harsh_or_kind.nil? ? @strict : harsh_or_kind
  @strict
end

#update(type, *args) ⇒ Object

Parameters:

  • type (Symbol)

    category i.e. class symbol of changes/errors reported

  • *args (*several_variants)

    information needed to accurately log the event; varies by change/error class

Raises:

  • (Exception)


79
80
81
82
83
84
85
86
# File 'lib/duxml/meta/history.rb', line 79

def update(type, *args)
  change_class = Duxml::const_get "#{type.to_s}Class".to_sym
  change_comp = change_class.new *args
  @nodes.unshift change_comp
  changed
  notify_observers(change_comp) unless change_comp.respond_to?(:error?)
  raise(Exception, change_comp.description) if strict? && type == :QualifyError
end