Class: Linen::Plugin
- Inherits:
-
Object
- Object
- Linen::Plugin
- Defined in:
- lib/linen/plugin.rb
Overview
Copyright 2007, LAIKA, Inc. #
#
Authors: #
* Ben Bleything <bbleything@laika.com> #
Defined Under Namespace
Classes: Argument, ArgumentError, PluginError, SimpleCommand, TwoPhaseCommand
Class Attribute Summary collapse
-
.commands ⇒ Object
readonly
Returns the value of attribute commands.
Class Method Summary collapse
- .argument(name, opts = {}) ⇒ Object
-
.arguments(*args) ⇒ Object
If args is empty, assume it was called like Plugin.arguments, so return the hash.
-
.cleanup(&block) ⇒ Object
multi-purpose method!.
- .command(name, hash = {}, &block) ⇒ Object
-
.description(input = nil) ⇒ Object
define the plugin’s description, or fetch it if nothing passed.
- .help ⇒ Object
- .inherited(plugin) ⇒ Object
- .short_name(short_name = nil) ⇒ Object
Class Attribute Details
.commands ⇒ Object (readonly)
Returns the value of attribute commands.
12 13 14 |
# File 'lib/linen/plugin.rb', line 12 def commands @commands end |
Class Method Details
.argument(name, opts = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/linen/plugin.rb', line 48 def self::argument( name, opts = {} ) @defined_arguments ||= IndifferentHash.new if opts[:error_message].nil? and opts['error_message'].nil? opts[ :error_message ] = "The value for #{name} is invalid." end @defined_arguments[ name ] = Argument.new( self, name, opts ) end |
.arguments(*args) ⇒ Object
If args is empty, assume it was called like Plugin.arguments, so return the hash.
61 62 63 64 65 66 67 68 69 |
# File 'lib/linen/plugin.rb', line 61 def self::arguments( *args ) @defined_arguments ||= IndifferentHash.new return @defined_arguments if args.empty? args.each do |arg| argument arg end end |
.cleanup(&block) ⇒ Object
multi-purpose method!
if passed a block, set this plugin’s cleanup proc to the block. if called without a block, execute the proc.
this is meant to allow plugins to clean up after themselves.
91 92 93 94 95 96 97 98 |
# File 'lib/linen/plugin.rb', line 91 def self::cleanup( &block ) if block_given? @cleanup_proc = block else # if we didn't define a proc, don't try to call it @cleanup_proc.call if @cleanup_proc end end |
.command(name, hash = {}, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/linen/plugin.rb', line 72 def self::command( name, hash = {}, &block ) @commands ||= IndifferentHash.new if hash[ :lookup_first ] command = TwoPhaseCommand.new( self, name, &block ) else command = SimpleCommand.new( self, name, &block ) end @commands[ name ] = command end |
.description(input = nil) ⇒ Object
define the plugin’s description, or fetch it if nothing passed
102 103 104 105 106 |
# File 'lib/linen/plugin.rb', line 102 def self::description( input = nil ) return @description unless input @description = input end |
.help ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/linen/plugin.rb', line 27 def self::help output = [] desc = description || "No help for #{short_name}" output << desc output << nil #blank line output << "Available commands:" output << nil #blank line commands.each do |name, command| output << "- #{name}" end output << nil #blank line output << "For detailed help on a command, enter \"help #{short_name} <command>\"".wrap return output.join( "\n" ) end |
.inherited(plugin) ⇒ Object
16 17 18 |
# File 'lib/linen/plugin.rb', line 16 def self::inherited( plugin ) Linen::PluginRegistry.instance.register plugin end |
.short_name(short_name = nil) ⇒ Object
21 22 23 24 |
# File 'lib/linen/plugin.rb', line 21 def self::short_name( short_name = nil ) @short_name = short_name if short_name return @short_name || self.to_s.downcase.gsub( /plugin$/, '' ) end |