Module: Greenhouse::Commands::Command::ClassMethods
- Defined in:
- lib/greenhouse/commands/command.rb
Instance Method Summary collapse
- #after_hooks ⇒ Object
- #append_after_hook(&block) ⇒ Object (also: #after_hook)
- #append_before_hook(&block) ⇒ Object (also: #before_hook)
- #before_hooks ⇒ Object
- #command_name(n = nil) ⇒ Object
- #command_summary(summary = nil) ⇒ Object (also: #summary)
- #prepend_after_hook(&block) ⇒ Object
- #prepend_before_hook(&block) ⇒ Object
- #run ⇒ Object
- #to_arg ⇒ Object
- #usage ⇒ Object
Instance Method Details
#after_hooks ⇒ Object
54 55 56 57 |
# File 'lib/greenhouse/commands/command.rb', line 54 def after_hooks @after_hooks ||= [] @after_hooks end |
#append_after_hook(&block) ⇒ Object Also known as: after_hook
43 44 45 46 |
# File 'lib/greenhouse/commands/command.rb', line 43 def append_after_hook(&block) @after_hooks ||= [] @after_hooks << block end |
#append_before_hook(&block) ⇒ Object Also known as: before_hook
59 60 61 62 |
# File 'lib/greenhouse/commands/command.rb', line 59 def append_before_hook(&block) @before_hooks ||= [] @before_hooks << block end |
#before_hooks ⇒ Object
70 71 72 73 |
# File 'lib/greenhouse/commands/command.rb', line 70 def before_hooks @before_hooks ||= [] @before_hooks end |
#command_name(n = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/greenhouse/commands/command.rb', line 13 def command_name(n=nil) @command_name = n unless n.nil? return @command_name unless @command_name.nil? self.name.underscore.split("/").last end |
#command_summary(summary = nil) ⇒ Object Also known as: summary
19 20 21 22 |
# File 'lib/greenhouse/commands/command.rb', line 19 def command_summary(summary=nil) @command_summary = summary unless summary.nil? @command_summary end |
#prepend_after_hook(&block) ⇒ Object
49 50 51 52 |
# File 'lib/greenhouse/commands/command.rb', line 49 def prepend_after_hook(&block) @after_hooks ||= [] @after_hooks.unshift block end |
#prepend_before_hook(&block) ⇒ Object
65 66 67 68 |
# File 'lib/greenhouse/commands/command.rb', line 65 def prepend_before_hook(&block) @before_hooks ||= [] @before_hooks.unshift block end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/greenhouse/commands/command.rb', line 29 def run begin @command ||= new before_hooks.each { |block| @command.instance_eval(&block) } @command.run after_hooks.each { |block| @command.instance_eval(&block) } rescue Exception => e puts e. puts e.backtrace if ::Greenhouse::CLI.debug? @command.usage if e.is_a?(Scripts::InvalidArgument) return end end |
#to_arg ⇒ Object
75 76 77 |
# File 'lib/greenhouse/commands/command.rb', line 75 def to_arg Scripts::Argument.new(command_name, :summary => command_summary) end |
#usage ⇒ Object
25 26 27 |
# File 'lib/greenhouse/commands/command.rb', line 25 def usage puts "usage: #{::Greenhouse::CLI.command_name} #{command_name} #{valid_arguments.to_s}" end |