Class: UML::SequenceDiagram
- Inherits:
-
Object
- Object
- UML::SequenceDiagram
- Includes:
- SequenceDiagramHelper
- Defined in:
- lib/uml/sequence_diagram.rb
Overview
Generates pic representation of program execution.
Defined Under Namespace
Classes: ObjectDefinition
Instance Method Summary collapse
-
#include(*args) ⇒ Object
Include methods of class or instance.
-
#initialize(config = nil) ⇒ SequenceDiagram
constructor
- Options: basename
-
You can give the actor a name.
- #to_pic ⇒ Object
-
#update(event, tracer) ⇒ Object
:nodoc: #.
Methods included from SequenceDiagramHelper
#pic_active, #pic_actor, #pic_complete, #pic_create_message, #pic_inactive, #pic_message, #pic_message_exchange, #pic_object, #pic_object_completions, #pic_object_definition, #pic_object_definitions, #pic_placeholder_object, #pic_return_message, #pic_step, #pic_variable, #pic_variable_definitions
Constructor Details
#initialize(config = nil) ⇒ SequenceDiagram
Options:
- basename
-
You can give the actor a name. Default is ‘Actor’.
- multiple_activation
-
If
true, and an activated object calls method with receiverself, object can be activated multiple times. Default isfalse. - object_sequence
-
You can sort the sequence of objects in output, if you give their names here.
Every object not included, will be printed after given ones in random order.
Defaults to
['Actor'], which ensures that ‘Actor’ is always the leftmost object. - pic_variables
-
Hash with variables for sequence.pic. See UMLGraph’s documentation for valid variables. Default {}.
- sequence_pic
-
give the position and name of UMLGraph’s sequence.pic file.
Default is ‘sequence.pic’, which means that the file has to be in the directory where pic2plot is called.
- split_inherited
-
If
trueincluded modules and superclasses are printed as discrete objects.Default is
false. - use_create_message
-
If method initialize is caught, a create_message is built instead of a normal call. Have in mind, that initialize is not allways used as constructor.
Default is
false. - parameter_callback
-
To get a pretty print of method args and returnvalues, you can give a proc here, that gets called for each argument or returnvalue.
Default is
lambda { |p| p.to_s }, but have a look at method callback in examples/sequence_diagram_generator.rb for a more sophisticated and recursive example.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/uml/sequence_diagram.rb', line 40 def initialize(config = nil) @config = { :basename => 'Actor', :split_inherited => false, :use_create_message => false, :multiple_activation => false, :sequence_pic => 'sequence.pic', :pic_variables => {}, :object_sequence => ['Actor'], :parameter_callback => lambda { |p| p.to_s } } @config.update(config) if config @object_definitions = {} @object_definitions[@config[:basename]] = ObjectDefinition.new(@config[:basename], :actor) = '' @tracer = HighlevelBacktracer.new @tracer.add_observer self end |
Instance Method Details
#include(*args) ⇒ Object
Include methods of class or instance.
The parameters are handed on to AspectR::wrap, so refer to the according documentation for how you can e.g. use Regexp.
:call-seq: include(klass, *methods)
68 69 70 |
# File 'lib/uml/sequence_diagram.rb', line 68 def include(*args) @tracer.include(*args) end |
#to_pic ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/uml/sequence_diagram.rb', line 72 def to_pic result = '' result << ".PS\n" result << "copy \"#{@config[:sequence_pic]}\";\n" result << pic_variable_definitions(@config[:pic_variables]) result << pic_object_definitions(object_definitions) result << () result << pic_object_completions(@object_definitions.values) result << '.PE' result end |
#update(event, tracer) ⇒ Object
:nodoc: #
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/uml/sequence_diagram.rb', line 84 def update(event, tracer) # :nodoc: # begin right = tracer.call_stack[-1] left = tracer.call_stack[-2] used_object = @config[:split_inherited] ? :real_object : :object right_label = right[used_object].name left_label = (left) ? left[used_object].name : @config[:basename] case event when :call if @config[:use_create_message] and right[:method_symbol] == :initialize @object_definitions[right_label] ||= ObjectDefinition.new(right_label, :placeholder_object ) << (@object_definitions[left_label], @object_definitions[right_label] ) else @object_definitions[right_label] ||= ObjectDefinition.new(right_label) << (@object_definitions[left_label], @object_definitions[right_label], right[:method_symbol], right[:args].collect(&@config[:parameter_callback]).join(',') ) end when :return << (@object_definitions[left_label], @object_definitions[right_label], @config[:parameter_callback].call(right[:returns]) ) end rescue Exception => e puts e puts e.backtrace exit 1 end end |