Module: Linen::Plugin::CommandInfrastructure
- Included in:
- SimpleCommand, TwoPhaseCommand
- Defined in:
- lib/linen/mixins/command_infrastructure.rb
Overview
Common methods factored out of the command classes.
Authors
-
Ben Bleything <[email protected]>
Copyright
Copyright © 2007 Laika, Inc.
This code released under the terms of the BSD license.
Version
$Id: simple_command.rb 391 2007-11-19 22:21:55Z bbleything $
Instance Method Summary collapse
- #action(&block) ⇒ Object
- #can_inspect? ⇒ Boolean
- #execute(workspace = Linen::Workspace.new) ⇒ Object
- #help ⇒ Object
-
#help_message(message) ⇒ Object
PLUGIN DEFINITION METHODS #.
- #initialize(plugin, name, &block) ⇒ Object
- #inspect(workspace = Linen::Workspace.new, &block) ⇒ Object
- #require_confirmation ⇒ Object
-
#requires_confirmation? ⇒ Boolean
HELPER METHODS #.
Instance Method Details
#action(&block) ⇒ Object
61 62 63 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 61 def action( &block ) @action_proc = block end |
#can_inspect? ⇒ Boolean
88 89 90 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 88 def can_inspect? @inspect_proc end |
#execute(workspace = Linen::Workspace.new) ⇒ Object
31 32 33 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 31 def execute( workspace = Linen::Workspace.new ) return workspace.instance_eval( &@action_proc ) end |
#help ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 36 def help output = [] output << @help_text.wrap output << nil # blank line # this map turns our list of args into a list like this: # <arg1> <arg2> <arg3> <arg4>... arg_list = @arguments.map {|a| "<#{a.to_s}>"}.join( ' ' ) output << "Usage: #{@plugin.short_name} #{name} #{arg_list}" return output.join( "\n" ) end |
#help_message(message) ⇒ Object
PLUGIN DEFINITION METHODS #
56 57 58 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 56 def ( ) @help_text = end |
#initialize(plugin, name, &block) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 21 def initialize( plugin, name, &block ) @plugin = plugin @name = name @arguments = [] @help_text = "No help for #{plugin.short_name} #{name}" self.instance_eval &block end |
#inspect(workspace = Linen::Workspace.new, &block) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 71 def inspect( workspace = Linen::Workspace.new, &block ) if block_given? @inspect_proc = block else return workspace.instance_eval( &@inspect_proc ) end end |
#require_confirmation ⇒ Object
66 67 68 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 66 def require_confirmation @require_confirmation = true end |
#requires_confirmation? ⇒ Boolean
HELPER METHODS #
84 85 86 |
# File 'lib/linen/mixins/command_infrastructure.rb', line 84 def requires_confirmation? @require_confirmation end |