Class: Emf::Model::Visitor

Inherits:
Object
  • Object
show all
Defined in:
lib/emf/model/visitor.rb

Direct Known Subclasses

Visitors::Dump, Visitors::Stats

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.visit_methodsObject (readonly)

Returns the value of attribute visit_methods.



19
20
21
# File 'lib/emf/model/visitor.rb', line 19

def visit_methods
  @visit_methods
end

Class Method Details

.register_visit(name, record_class) ⇒ Object

Record classes call this to declare a visit method name. The base class installs a no-op default so subclasses can override only what they need.



12
13
14
15
16
17
# File 'lib/emf/model/visitor.rb', line 12

def register_visit(name, record_class)
  @visit_methods[name] = record_class
  return if method_defined?(name)

  define_method(name) { |_| nil }
end

.visit_all(visitor, metafile) ⇒ Object

Walk every record in the metafile (and a nested EMF+ sub-stream if any), dispatching to the matching visit_* method.



23
24
25
26
27
28
# File 'lib/emf/model/visitor.rb', line 23

def visit_all(visitor, metafile)
  metafile.each { |record| record.accept(visitor) }
  nested = metafile.emf_plus
  visit_all(visitor, nested) if nested.is_a?(Emf::Model::Metafile)
  visitor
end

Instance Method Details

#visit(record) ⇒ Object



31
32
33
34
# File 'lib/emf/model/visitor.rb', line 31

def visit(record)
  record.accept(self)
  self
end

#visit_all(metafile) ⇒ Object



36
37
38
39
# File 'lib/emf/model/visitor.rb', line 36

def visit_all(metafile)
  self.class.visit_all(self, metafile)
  self
end