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

Instance Attribute Summary

Attributes included from Reportable

#observer_peers

Attributes included from Duxml

#doc

Attributes included from Saxer

#io

Instance Method Summary collapse

Methods included from Reportable

#add_observer

Methods included from Duxml

#load, #log, #save, #validate

Methods included from Saxer

#sax

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



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

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



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

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



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

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

#latestChangeClass, ErrorClass

Returns the latest event.

Returns:



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

def latest
  events[0]
end

#strict?(strict_or_false = 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



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

def strict?(strict_or_false=nil)
  @strict = strict_or_false.nil? ? @strict : strict_or_false
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)


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

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

#xmlDoc

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

Returns:

  • (Doc)

    returns self as XML document



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

def xml
  h = Element.new('history')
  events.each do |event| h << event.xml end
  h
end