Class: Apimaster::Generators::Command
- Defined in:
- lib/apimaster/generators/command.rb
Overview
Generator commands delegate Apimaster::Generators::Base and implement a standard set of actions. Their behavior is defined by the way they respond to these actions: Create brings life; Destroy brings death; List passively observes.
Commands are invoked by replaying (or rewinding) the generator’s manifest of actions. See Apimaster::Generators::Manifest and are required to override.
Commands allows generators to “plug in” invocation behavior, which corresponds to the GoF Strategy pattern.
Direct Known Subclasses
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#active, #args, #destination_root, #logger, #source_root, #spec, #stdout
Attributes included from Options
Instance Method Summary collapse
-
#class_collisions(*class_names) ⇒ Object
Does nothing for all commands except Create.
- #dependency(generator_name, args, runtime_options = {}) ⇒ Object
-
#destination_path(relative_destination) ⇒ Object
Return the full path from the destination root for the given path.
-
#invoke! ⇒ Object
Replay action manifest.
-
#readme(*args) ⇒ Object
Does nothing for all commands except Create.
-
#source_path(relative_source) ⇒ Object
Return the full path from the source root for the given path.
-
#write_manifest ⇒ Object
Does nothing for all commands except Create.
Methods inherited from Base
#after_generate, #base_name, #camelize, #initialize, #manifest, #pluralize, #run
Methods included from Options
Constructor Details
This class inherits a constructor from Apimaster::Generators::Base
Instance Method Details
#class_collisions(*class_names) ⇒ Object
Does nothing for all commands except Create.
66 67 |
# File 'lib/apimaster/generators/command.rb', line 66 def class_collisions(*class_names) end |
#dependency(generator_name, args, runtime_options = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/apimaster/generators/command.rb', line 59 def dependency(generator_name, args, = {}) logger.dependency(generator_name) do self.class.new(instance(generator_name, args, ())).invoke! end end |
#destination_path(relative_destination) ⇒ Object
Return the full path from the destination root for the given path. Example for destination_root = ‘/dest’:
destination_path('some/path.rb') == '/dest/some/path.rb'
49 50 51 |
# File 'lib/apimaster/generators/command.rb', line 49 def destination_path(relative_destination) File.(File.join(destination_root, relative_destination)) end |
#invoke! ⇒ Object
Replay action manifest. RewindBase subclass rewinds manifest.
54 55 56 57 |
# File 'lib/apimaster/generators/command.rb', line 54 def invoke! manifest.replay(self) after_generate end |
#readme(*args) ⇒ Object
Does nothing for all commands except Create.
70 71 |
# File 'lib/apimaster/generators/command.rb', line 70 def readme(*args) end |
#source_path(relative_source) ⇒ Object
Return the full path from the source root for the given path. Example for source_root = ‘/source’:
source_path('some/path.rb') == '/source/some/path.rb'
The given path may include a colon ‘:’ character to indicate that the file belongs to another generator. This notation allows any generator to borrow files from another. Example:
source_path('model:fixture.yml') = '/model/source/path/fixture.yml'
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/apimaster/generators/command.rb', line 30 def source_path(relative_source) # Check whether we're referring to another generator's file. name, path = relative_source.split(':', 2) # If not, return the full path to our source file. if path.nil? File.join(source_root, name) # Otherwise, ask our referral for the file. else # FIXME: this is broken, though almost always true. Others' # source_root are not necessarily the templates dir. File.join(self.class.lookup(name).path, 'templates', path) end end |
#write_manifest ⇒ Object
Does nothing for all commands except Create.
74 75 |
# File 'lib/apimaster/generators/command.rb', line 74 def write_manifest end |