4 # Manifest captures the actions a generator performs. Instantiate
5 # a manifest with an optional target object, hammer it with actions,
6 # then replay or rewind on the object of your choice.
9 # manifest = Manifest.new { |m|
10 # m.make_directory '/foo'
11 # m.create_file '/foo/bar.txt'
13 # manifest.replay(creator)
14 # manifest.rewind(destroyer)
18 # Take a default action target. Yield self if block given.
19 def initialize(target
= nil)
20 @target, @actions = target
, []
21 yield self if block_given
?
25 def method_missing(action
, *args
, &block
)
26 @actions << [action
, args
, block
]
29 # Replay recorded actions.
30 def replay(target
= nil)
31 send_actions(target
|| @target, @actions)
34 # Rewind recorded actions.
35 def rewind(target
= nil)
36 send_actions(target
|| @target, @actions.reverse
)
39 # Erase recorded actions.
45 def send_actions(target
, actions
)
46 actions
.each
do |method
, args
, block
|
47 target
.send(method
, *args
, &block
)