trailblazer-activity 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee1dccefcc5ecdb9c4a24901de3e68ae14542b29
4
- data.tar.gz: cb17a9035ef5193301f01f58659a156616c1d42e
3
+ metadata.gz: e6d5b085e32a6c4333c666ce48975f2b99180ef8
4
+ data.tar.gz: 611e2db6f13e3e5ff629df25a584b5cfca347244
5
5
  SHA512:
6
- metadata.gz: 92fc5d5969bf80a125d284d7615152655fbeb5af46dd1cac3e9927962a88eb751504976806336cbdcab55b577504e07494a27348a60bb25b565b36e60e42f9c2
7
- data.tar.gz: d58607ae4df287ed931770f30a2c6017ebf693a28d252326605940f0f6c6c03da8441c5fe66af6abf56c21c6123719b2aafbae43a820aaf27390631314817990
6
+ metadata.gz: a9a7f0ce9ac2c94d618a8fdc933354b7228f9d63050f43f8adeac26afc165ba798ac9a8fe9e414648004ef00b07f20ac8c2881c630f22f915ba9d178eab5d78c
7
+ data.tar.gz: 20863cf5baab210d02c72eea6afb0da2c1151d0182c33a0158d69141d9ba20e83ca019aec0d38e83c37443672decbeeac6f52be4835af5e8a1f0680cbc523e00
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.3
2
+
3
+ * Introduce `Activity#outputs` and ditch `#end_events`.
4
+
1
5
  # 0.1.2
2
6
 
3
7
  * Consistent return values for all graph operations: `node, edge`.
@@ -86,7 +86,15 @@ module Trailblazer
86
86
  end
87
87
 
88
88
  def end_events
89
- @circuit.to_fields[1]
89
+ outputs.keys
90
+ end
91
+
92
+ # Returns a hash mapping the circuit {Event} to its meta data.
93
+ #
94
+ # activity.outputs #=> { #<End ..> => { role: :success }, #<End ..> => { role: :failure } }
95
+ def outputs
96
+ # DISCUSS: add more meta data?
97
+ ::Hash[ graph.find_all { |node| graph.successors(node).size == 0 }.collect { |node| [ node[:_wrapped], { role: node[:role] } ] } ]
90
98
  end
91
99
 
92
100
  # @private
@@ -97,9 +105,6 @@ module Trailblazer
97
105
  private
98
106
 
99
107
  def to_circuit(graph)
100
- end_events = graph.find_all { |node| graph.successors(node).size == 0 } # Find leafs of graph.
101
- .collect { |n| n[:_wrapped] } # unwrap the actual End event instance from the Node.
102
-
103
108
  Circuit.new(graph.to_h( include_leafs: false ), end_events, {})
104
109
  end
105
110
 
@@ -1,3 +1,5 @@
1
+ require "forwardable"
2
+
1
3
  module Trailblazer
2
4
  # Note that Graph is a superset of a real directed graph. For instance, it might contain detached nodes.
3
5
  # == Design
@@ -6,7 +8,7 @@ module Trailblazer
6
8
  module Activity::Graph
7
9
  # Task => { name: "Nested{Task}", type: :subprocess, boundary_events: { Circuit::Left => {} } }
8
10
 
9
- # TODO: make Edge, Node, Start Hash::Immutable ?
11
+ # Edge keeps references to its peer nodes via the `:source` and `:target` options.
10
12
  class Edge
11
13
  def initialize(data)
12
14
  @data = data.freeze
@@ -21,6 +23,7 @@ module Trailblazer
21
23
  end
22
24
  end
23
25
 
26
+ # Node does only save meta data, and has *no* references to edges.
24
27
  class Node < Edge
25
28
  end
26
29
 
@@ -30,31 +33,7 @@ module Trailblazer
30
33
  super
31
34
  end
32
35
 
33
- # Single entry point for adding nodes and edges to the graph.
34
- # @return target Node
35
- # @return edge Edge the edge created connecting source and target.
36
- def connect_for!(source, edge_args, target, old_edge:nil)
37
- edge = Edge(source, edge_args, target)
38
-
39
- self[:graph][source][edge] = target
40
-
41
- self[:graph][source].delete(old_edge) # FIXME: shouldn't be here
42
-
43
- return target, edge
44
- end
45
-
46
- def add!(node_args)
47
- new_node = Node(*node_args)
48
-
49
- raise IllegalNodeError.new("The ID `#{new_node[:id]}` has been added before.") if find_all( new_node[:id] ).any?
50
-
51
- self[:graph][new_node] = {}
52
- new_node
53
- end
54
-
55
- private :connect_for!, :add!
56
-
57
- # Builds a node from the provided `:target` arguments.
36
+ # Builds a node from the provided `:target` arguments and attaches it via `:edge` to `:source`.
58
37
  # @param target: Array wrapped, options
59
38
  def attach!(target:raise, edge:raise, source:self)
60
39
  target = add!(target)
@@ -63,8 +42,8 @@ module Trailblazer
63
42
  end
64
43
 
65
44
  def connect!(target:raise, edge:raise, source:self)
66
- target = target.kind_of?(Node) ? target : (find_all { |_target| _target[:id] == target }[0] || raise( "#{target} not found")) # FIXME: only needed for recompile_activity.
67
- source = source.kind_of?(Node) ? source : (find_all { |_source| _source[:id] == source }[0] || raise( "#{source} not found"))
45
+ target = target.kind_of?(Node) ? target : (find_all(target)[0] || raise( "#{target} not found")) # FIXME: only needed for recompile_activity.
46
+ source = source.kind_of?(Node) ? source : (find_all(source)[0] || raise( "#{source} not found"))
68
47
 
69
48
  connect_for!(source, edge, target)
70
49
  end
@@ -73,15 +52,11 @@ module Trailblazer
73
52
  old_node = find_all(old_node)[0] || raise( "#{old_node} not found") unless old_node.kind_of?(Node) # FIXME: do we really need this?
74
53
  new_node = add!(node)
75
54
 
76
- incoming_tuples = predecessors(old_node)
77
- rewired_incoming_connections = incoming_tuples.find_all { |(node, edge)| incoming.(edge) }
55
+ incoming_edges = predecessors(old_node)
56
+ rewired_edges = incoming_edges.find_all { |(node, edge)| incoming.(edge) }
78
57
 
79
58
  # rewire old_task's predecessors to new_task.
80
- if rewired_incoming_connections.any? # the opposite happens when we're inserting "before" an orphaned node.
81
- rewired_incoming_connections.each { |node, edge|
82
- node, edge = connect_for!(node, [edge[:_wrapped], edge.to_h], new_node, old_edge: edge)
83
- }
84
- end
59
+ rewired_edges.each { |left_node, edge| reconnect!(left_node, edge, new_node) }
85
60
 
86
61
  # connect new_task --> old_task.
87
62
  if outgoing
@@ -98,16 +73,6 @@ module Trailblazer
98
73
  nodes.find_all(& block || ->(node) { node[:id] == id })
99
74
  end
100
75
 
101
- def Edge(source, (wrapped, options), target) # FIXME: test required id. test source and target
102
- id = "#{source[:id]}-#{wrapped}-#{target[:id]}"
103
- edge = Edge.new(options.merge( _wrapped: wrapped, id: id, source: source, target: target ))
104
- end
105
-
106
- # @private
107
- def Node(wrapped, id:raise("No ID was provided for #{wrapped}"), **options)
108
- Node.new( options.merge( id: id, _wrapped: wrapped ) )
109
- end
110
-
111
76
  def predecessors(target_node)
112
77
  self[:graph].each_with_object([]) do |(node, connections), ary|
113
78
  connections.each { |edge, target| target == target_node && ary << [node, edge] }
@@ -133,6 +98,54 @@ module Trailblazer
133
98
 
134
99
  hash
135
100
  end
101
+
102
+ # @private
103
+ def Node(wrapped, id:raise("No ID was provided for #{wrapped}"), **options)
104
+ Node.new( options.merge( id: id, _wrapped: wrapped ) )
105
+ end
106
+
107
+ private
108
+
109
+ # Single entry point for adding nodes and edges to the graph.
110
+ # @private
111
+ # @return target Node
112
+ # @return edge Edge the edge created connecting source and target.
113
+ def connect_for!(source, edge_args, target)
114
+ edge = Edge(source, edge_args, target)
115
+
116
+ self[:graph][source][edge] = target
117
+
118
+ return target, edge
119
+ end
120
+
121
+ # Removes edge.
122
+ # @private
123
+ def unconnect!(node, edge)
124
+ self[:graph][node].delete(edge)
125
+ end
126
+
127
+ # @private
128
+ # Create a Node and add it to the graph, without connecting it.
129
+ def add!(node_args)
130
+ new_node = Node(*node_args)
131
+
132
+ raise IllegalNodeError.new("The ID `#{new_node[:id]}` has been added before.") if find_all( new_node[:id] ).any?
133
+
134
+ self[:graph][new_node] = {}
135
+ new_node
136
+ end
137
+
138
+ # @private
139
+ def reconnect!(left_node, edge, new_node)
140
+ unconnect!(left_node, edge) # dump the old edge.
141
+ connect_for!(left_node, [ edge[:_wrapped], edge.to_h ], new_node)
142
+ end
143
+
144
+ # @private
145
+ def Edge(source, (wrapped, options), target) # FIXME: test required id. test source and target
146
+ id = "#{source[:id]}-#{wrapped}-#{target[:id]}"
147
+ edge = Edge.new(options.merge( _wrapped: wrapped, id: id, source: source, target: target ))
148
+ end
136
149
  end
137
150
 
138
151
  def self.Start(wrapped, graph:{}, **data, &block)
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Activity
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-23 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hirb
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.6.8
131
+ rubygems_version: 2.6.12
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: The main element for Trailblazer's BPMN-compliant workflows.