Class: RubiGen::Manifest

Inherits:
Object show all
Defined in:
lib/rubigen/manifest.rb

Overview

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)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target = nil) {|_self| ... } ⇒ Manifest

Take a default action target. Yield self if block given.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
# File 'lib/rubigen/manifest.rb', line 18

def initialize(target = nil)
  @target, @actions = target, []
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, *args, &block) ⇒ Object

Record an action.



24
25
26
# File 'lib/rubigen/manifest.rb', line 24

def method_missing(action, *args, &block)
  @actions << [action, args, block]
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



15
16
17
# File 'lib/rubigen/manifest.rb', line 15

def target
  @target
end

Instance Method Details

#eraseObject

Erase recorded actions.



39
40
41
# File 'lib/rubigen/manifest.rb', line 39

def erase
  @actions = []
end

#replay(target = nil) ⇒ Object

Replay recorded actions.



29
30
31
# File 'lib/rubigen/manifest.rb', line 29

def replay(target = nil)
  send_actions(target || @target, @actions)
end

#rewind(target = nil) ⇒ Object

Rewind recorded actions.



34
35
36
# File 'lib/rubigen/manifest.rb', line 34

def rewind(target = nil)
  send_actions(target || @target, @actions.reverse)
end