Skip to content

Commit d580508

Browse files
dvanderbeekgeekq
authored andcommitted
Add ability to include partial workflow definitions for composability
1 parent 970f839 commit d580508

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/workflow/specification.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def state_names
2020

2121
private
2222

23+
def include(proc)
24+
instance_eval(&proc)
25+
end
26+
2327
def state(name, meta = {:meta => {}}, &events_and_etc)
2428
# meta[:meta] to keep the API consistent..., gah
2529
new_state = Workflow::State.new(name, self, meta[:meta])

test/main_test.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ class MainTest < Minitest::Test
9292
assert_equal 'one', c.new.current_state.to_s
9393
end
9494

95+
test 'including a child workflow definition for composable workflows' do
96+
child = Proc.new do
97+
state :two
98+
end
99+
100+
c = Class.new
101+
c.class_eval do
102+
include Workflow
103+
workflow do
104+
state :one
105+
include child
106+
state :three
107+
end
108+
end
109+
assert_equal [:one, :two, :three], c.workflow_spec.states.keys
110+
end
111+
95112
# TODO Consider following test case:
96113
# test 'multiple events with the same name and different arguments lists from different states'
97114

@@ -354,4 +371,3 @@ def capture_streams
354371
end
355372

356373
end
357-

0 commit comments

Comments
 (0)