Class: Rails::Generator::Manifest
- Defined in:
- lib/rails_generator/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
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#erase ⇒ Object
Erase recorded actions.
-
#initialize(target = nil) {|_self| ... } ⇒ Manifest
constructor
Take a default action target.
-
#method_missing(action, *args, &block) ⇒ Object
Record an action.
-
#replay(target = nil) ⇒ Object
Replay recorded actions.
-
#rewind(target = nil) ⇒ Object
Rewind recorded actions.
Constructor Details
#initialize(target = nil) {|_self| ... } ⇒ Manifest
Take a default action target. Yield self if block given.
19 20 21 22 |
# File 'lib/rails_generator/manifest.rb', line 19 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.
25 26 27 |
# File 'lib/rails_generator/manifest.rb', line 25 def method_missing(action, *args, &block) @actions << [action, args, block] end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
16 17 18 |
# File 'lib/rails_generator/manifest.rb', line 16 def target @target end |
Instance Method Details
#erase ⇒ Object
Erase recorded actions.
40 41 42 |
# File 'lib/rails_generator/manifest.rb', line 40 def erase @actions = [] end |
#replay(target = nil) ⇒ Object
Replay recorded actions.
30 31 32 |
# File 'lib/rails_generator/manifest.rb', line 30 def replay(target = nil) send_actions(target || @target, @actions) end |
#rewind(target = nil) ⇒ Object
Rewind recorded actions.
35 36 37 |
# File 'lib/rails_generator/manifest.rb', line 35 def rewind(target = nil) send_actions(target || @target, @actions.reverse) end |