Module: Duxml::Rule

Includes:
Reportable
Included in:
RuleClass
Defined in:
lib/duxml/meta/grammar/rule.rb,
lib/duxml/meta/grammar/rule.rb

Overview

contains methods to apply Duxml::RuleClass to XML edit or validate events

Instance Attribute Summary

Attributes included from Reportable

#observer_peers

Instance Method Summary collapse

Methods included from Reportable

#add_observer

Instance Method Details

#applies_to?(change_or_pattern) ⇒ Boolean

Returns whether this rule does in fact apply.

Parameters:

Returns:

  • (Boolean)

    whether this rule does in fact apply



48
49
50
51
# File 'lib/duxml/meta/grammar/rule.rb', line 48

def applies_to?(change_or_pattern)
  pattern_type = change_or_pattern.subject.name
  subject == pattern_type
end

#descriptionString

Returns default description for a Rule.

Returns:

  • (String)

    default description for a Rule



54
55
56
57
# File 'lib/duxml/meta/grammar/rule.rb', line 54

def description
  statement_str = (statement.is_a?(String) ? statement : statement.inspect).gsub('\b','')
  %(#{relationship.capitalize} Rule that <#{subject}>'s #{relationship} must match '#{statement_str}')
end

#historyHistoryClass

Returns history to which this rule will report errors.

Returns:

  • (HistoryClass)

    history to which this rule will report errors



42
43
44
# File 'lib/duxml/meta/grammar/rule.rb', line 42

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

#qualify(change_or_pattern) ⇒ Boolean

Duxml::Rule’s #qualify is only used to report errors found by its subclasses’ #qualify methods

Parameters:

Returns:

  • (Boolean)

    always false; this method should always be subclassed to apply that specific rule type’s #qualify



35
36
37
38
39
# File 'lib/duxml/meta/grammar/rule.rb', line 35

def qualify(change_or_pattern)
  type = (change_or_pattern.respond_to?(:time_stamp)) ? :QualifyError : :ValidateError
  report(type, change_or_pattern)
  false
end