adding-help: commit created loader

This commit is contained in:
rkiel
2015-06-07 22:01:10 -04:00
parent 218fa5a29c
commit b49ee451a6
4 changed files with 62 additions and 29 deletions

28
lib/feature/loader.rb Normal file
View File

@@ -0,0 +1,28 @@
module Feature
class Loader
attr_reader :commands, :default
def initialize commands, default
@commands = commands
@default = default
end
def create key, argv
key = default unless commands.include? key
require_relative "./#{key}"
klass = Module.const_get "Feature::#{key.to_s.capitalize}"
klass.new(argv)
end
def create_all argv
commands.map { |x| create(x,argv) }
end
def search pattern
regexp = Regexp.new(pattern)
commands.select { |x| regexp.match(x.to_s) }
end
end
end