trailblazer-activity 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/Gemfile +2 -0
- data/lib/trailblazer/activity.rb +2 -2
- data/lib/trailblazer/activity/graph.rb +46 -35
- data/lib/trailblazer/activity/version.rb +1 -1
- data/lib/trailblazer/circuit/trace.rb +1 -1
- data/lib/trailblazer/circuit/wrap.rb +2 -2
- data/trailblazer-activity.gemspec +3 -2
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee1dccefcc5ecdb9c4a24901de3e68ae14542b29
|
4
|
+
data.tar.gz: cb17a9035ef5193301f01f58659a156616c1d42e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92fc5d5969bf80a125d284d7615152655fbeb5af46dd1cac3e9927962a88eb751504976806336cbdcab55b577504e07494a27348a60bb25b565b36e60e42f9c2
|
7
|
+
data.tar.gz: d58607ae4df287ed931770f30a2c6017ebf693a28d252326605940f0f6c6c03da8441c5fe66af6abf56c21c6123719b2aafbae43a820aaf27390631314817990
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 0.1.2
|
2
|
+
|
3
|
+
* Consistent return values for all graph operations: `node, edge`.
|
4
|
+
* `Edge` now always gets an id.
|
5
|
+
* `#connect_for!` always throws away the old edge, fixing a bug where graph and circuit would look different.
|
6
|
+
* Internal simplifications for `Graph` alteration methods.
|
7
|
+
|
1
8
|
# 0.1.1
|
2
9
|
|
3
10
|
* Fix loading order.
|
data/Gemfile
CHANGED
data/lib/trailblazer/activity.rb
CHANGED
@@ -18,7 +18,7 @@ module Trailblazer
|
|
18
18
|
# Only way to build an Activity.
|
19
19
|
def self.from_wirings(wirings, &block)
|
20
20
|
start_evt = Circuit::Start.new(:default)
|
21
|
-
start_args = [ start_evt, { type: :event, id:
|
21
|
+
start_args = [ start_evt, { type: :event, id: "Start.default" } ]
|
22
22
|
|
23
23
|
start = block ? Graph::Start( *start_args, &block ) : Graph::Start(*start_args)
|
24
24
|
|
@@ -42,7 +42,7 @@ module Trailblazer
|
|
42
42
|
# end
|
43
43
|
def self.from_hash(end_evt=Circuit::End.new(:default), start_evt=Circuit::Start.new(:default), &block)
|
44
44
|
hash = yield(start_evt, end_evt)
|
45
|
-
graph = Graph::Start( start_evt, id:
|
45
|
+
graph = Graph::Start( start_evt, id: "Start.default" )
|
46
46
|
|
47
47
|
hash.each do |source_task, connections|
|
48
48
|
source = graph.find_all { |node| node[:_wrapped] == source_task }.first or raise "#{source_task} unknown"
|
@@ -9,12 +9,16 @@ module Trailblazer
|
|
9
9
|
# TODO: make Edge, Node, Start Hash::Immutable ?
|
10
10
|
class Edge
|
11
11
|
def initialize(data)
|
12
|
-
@data = data
|
12
|
+
@data = data.freeze
|
13
13
|
end
|
14
14
|
|
15
15
|
def [](key)
|
16
16
|
@data[key]
|
17
17
|
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
@data.to_h
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
class Node < Edge
|
@@ -27,53 +31,61 @@ module Trailblazer
|
|
27
31
|
end
|
28
32
|
|
29
33
|
# Single entry point for adding nodes and edges to the graph.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
+
|
34
39
|
self[:graph][source][edge] = target
|
40
|
+
|
41
|
+
self[:graph][source].delete(old_edge) # FIXME: shouldn't be here
|
42
|
+
|
43
|
+
return target, edge
|
35
44
|
end
|
36
|
-
private :connect_for!
|
37
45
|
|
38
|
-
|
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.
|
58
|
+
# @param target: Array wrapped, options
|
39
59
|
def attach!(target:raise, edge:raise, source:self)
|
40
|
-
target =
|
60
|
+
target = add!(target)
|
41
61
|
|
42
62
|
connect!(target: target, edge: edge, source: source)
|
43
63
|
end
|
44
64
|
|
45
65
|
def connect!(target:raise, edge:raise, source:self)
|
46
|
-
target = target.kind_of?(Node) ? target : (find_all { |_target| _target[:id] == target }[0] || raise( "#{target} not found"))
|
66
|
+
target = target.kind_of?(Node) ? target : (find_all { |_target| _target[:id] == target }[0] || raise( "#{target} not found")) # FIXME: only needed for recompile_activity.
|
47
67
|
source = source.kind_of?(Node) ? source : (find_all { |_source| _source[:id] == source }[0] || raise( "#{source} not found"))
|
48
68
|
|
49
|
-
edge = Edge(*edge)
|
50
|
-
|
51
69
|
connect_for!(source, edge, target)
|
52
|
-
|
53
|
-
target
|
54
70
|
end
|
55
71
|
|
56
72
|
def insert_before!(old_node, node:raise, outgoing:nil, incoming:raise)
|
57
|
-
old_node = find_all(old_node)[0] || raise( "#{old_node} not found") unless old_node.kind_of?(Node)
|
58
|
-
new_node =
|
73
|
+
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
|
+
new_node = add!(node)
|
59
75
|
|
60
|
-
|
61
|
-
|
62
|
-
incoming_tuples = predecessors(old_node)
|
63
|
-
rewired_connections = incoming_tuples.find_all { |(node, edge)| incoming.(edge) }
|
76
|
+
incoming_tuples = predecessors(old_node)
|
77
|
+
rewired_incoming_connections = incoming_tuples.find_all { |(node, edge)| incoming.(edge) }
|
64
78
|
|
65
79
|
# rewire old_task's predecessors to new_task.
|
66
|
-
if
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
+
}
|
70
84
|
end
|
71
85
|
|
72
86
|
# connect new_task --> old_task.
|
73
87
|
if outgoing
|
74
|
-
edge =
|
75
|
-
|
76
|
-
connect_for!(new_node, edge, old_node)
|
88
|
+
node, edge = connect_for!(new_node, outgoing, old_node)
|
77
89
|
end
|
78
90
|
|
79
91
|
return new_node
|
@@ -83,20 +95,19 @@ module Trailblazer
|
|
83
95
|
nodes = self[:graph].keys + self[:graph].values.collect(&:values).flatten
|
84
96
|
nodes = nodes.uniq
|
85
97
|
|
86
|
-
block
|
87
|
-
|
88
|
-
nodes.find_all(&block)
|
98
|
+
nodes.find_all(& block || ->(node) { node[:id] == id })
|
89
99
|
end
|
90
100
|
|
91
|
-
def Edge(wrapped, options)
|
92
|
-
|
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 ))
|
93
104
|
end
|
94
105
|
|
95
|
-
|
96
|
-
|
106
|
+
# @private
|
107
|
+
def Node(wrapped, id:raise("No ID was provided for #{wrapped}"), **options)
|
108
|
+
Node.new( options.merge( id: id, _wrapped: wrapped ) )
|
97
109
|
end
|
98
110
|
|
99
|
-
# private
|
100
111
|
def predecessors(target_node)
|
101
112
|
self[:graph].each_with_object([]) do |(node, connections), ary|
|
102
113
|
connections.each { |edge, target| target == target_node && ary << [node, edge] }
|
@@ -104,7 +115,7 @@ module Trailblazer
|
|
104
115
|
end
|
105
116
|
|
106
117
|
def successors(node)
|
107
|
-
( self[:graph][node] ||
|
118
|
+
( self[:graph][node] || [] ).collect { |edge, target| [target, edge] }
|
108
119
|
end
|
109
120
|
|
110
121
|
def to_h(include_leafs:true)
|
@@ -32,7 +32,7 @@ module Trailblazer
|
|
32
32
|
def self.wirings
|
33
33
|
[
|
34
34
|
[ :insert_before!, "task_wrap.call_task", node: [ Trace.method(:capture_args), id: "task_wrap.capture_args" ], outgoing: [ Right, {} ], incoming: ->(*) { true } ],
|
35
|
-
[ :insert_before!,
|
35
|
+
[ :insert_before!, "End.default", node: [ Trace.method(:capture_return), id: "task_wrap.capture_return" ], outgoing: [ Right, {} ], incoming: ->(*) { true } ],
|
36
36
|
]
|
37
37
|
end
|
38
38
|
|
@@ -79,8 +79,8 @@ class Trailblazer::Circuit
|
|
79
79
|
def self.initial_activity
|
80
80
|
Trailblazer::Activity.from_wirings(
|
81
81
|
[
|
82
|
-
[ :attach!, target: [ End.new(:default), type: :event, id:
|
83
|
-
[ :insert_before!,
|
82
|
+
[ :attach!, target: [ End.new(:default), type: :event, id: "End.default" ], edge: [ Right, {} ] ],
|
83
|
+
[ :insert_before!, "End.default", node: [ Call, id: "task_wrap.call_task" ], outgoing: [ Right, {} ], incoming: ->(*) { true } ]
|
84
84
|
]
|
85
85
|
)
|
86
86
|
end
|
@@ -20,11 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
+
spec.add_dependency "hirb"
|
24
|
+
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.14"
|
24
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
27
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
-
|
27
|
-
spec.add_dependency "hirb"
|
28
|
+
spec.add_development_dependency "trailblazer-test"
|
28
29
|
|
29
30
|
spec.required_ruby_version = '>= 2.0.0'
|
30
31
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-activity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2017-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hirb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,13 +67,13 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '5.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: trailblazer-test
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
|
-
type: :
|
76
|
+
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|