Class: BP::Main

Inherits:
Thor
  • Object
show all
Defined in:
lib/bp/main.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

If a task is not found on BP::Main, method missing is invoked and BP::Main is then responsable for finding the task in all classes.



10
11
12
13
14
15
16
# File 'lib/bp/main.rb', line 10

def method_missing(meth, *args)
  meth = meth.to_s
  klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
  self.class.handle_no_task_error(task, false) if klass.nil?
  args.unshift(task) if task
  klass.start(args, :shell => self.shell)
end

Instance Method Details

#help(search = "") ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bp/main.rb', line 20

def help(search="")
  if search == ''
    print_table({ 'bp help COMMAND' => 'Print help for a command' } , :truncate => true)
    say
  end

  search = ".*#{search}" if options["substring"]
  search = /^#{search}.*/i
  group  = options[:group] || "standard"

  klasses = Thor::Base.subclasses.select do |k|
    (options[:all] || k.group == group) && k.namespace =~ search
  end

  display_klasses(klasses)
end