Manifest captures the actions a generator performs. Instantiate a manifest with an optional target object, hammer it with actions, then replay or rewind on the object of your choice.
Example:
manifest = Manifest.new { |m| m.make_directory '/foo' m.create_file '/foo/bar.txt' } manifest.replay(creator) manifest.rewind(destroyer)
Take a default action target. Yield self if block given.
# File lib/rubigen/manifest.rb, line 18 def initialize(target = nil) @target, @actions = target, [] yield self if block_given? end
Erase recorded actions.
# File lib/rubigen/manifest.rb, line 39 def erase @actions = [] end
Record an action.
# File lib/rubigen/manifest.rb, line 24 def method_missing(action, *args, &block) @actions << [action, args, block] end
Replay recorded actions.
# File lib/rubigen/manifest.rb, line 29 def replay(target = nil) send_actions(target || @target, @actions) end
Rewind recorded actions.
# File lib/rubigen/manifest.rb, line 34 def rewind(target = nil) send_actions(target || @target, @actions.reverse) end