Module: Lux::Plugin
Constant Summary collapse
- PLUGIN =
{}
Instance Method Summary collapse
-
#folders(namespace = :main) ⇒ Object
get all folders in a namespace.
- #get(name) ⇒ Object
- #keys ⇒ Object
-
#load(arg) ⇒ Object
load specific plugin Lux.plugin :foo Lux.plugin ‘foo/bar’ Lux.plugin.folders Lux.plugin(:api).folder.
- #loaded ⇒ Object
- #plugins ⇒ Object
Instance Method Details
#folders(namespace = :main) ⇒ Object
get all folders in a namespace
59 60 61 62 63 |
# File 'lib/lux/plugin/plugin.rb', line 59 def folders namespace=:main list = PLUGIN.values list.select { |it| it.namespace.include?(namespace) } list.map { |it| it.folder } end |
#get(name) ⇒ Object
42 43 44 |
# File 'lib/lux/plugin/plugin.rb', line 42 def get name PLUGIN[name.to_s] || die('Plugin "%s" not loaded' % name) end |
#keys ⇒ Object
50 51 52 |
# File 'lib/lux/plugin/plugin.rb', line 50 def keys PLUGIN.keys end |
#load(arg) ⇒ Object
load specific plugin Lux.plugin :foo Lux.plugin ‘foo/bar’ Lux.plugin.folders Lux.plugin(:api).folder
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lux/plugin/plugin.rb', line 12 def load arg arg = arg.to_s if arg.is_a?(Symbol) if arg.is_a?(String) arg = arg.include?('/') ? { folder: arg } : { name: arg } end opts = arg.to_hwia :name, :folder, :namespace opts.name ||= opts.folder.split('/').last opts.name = opts.name.to_s opts.folder ||= Lux.fw_root.join('plugins', opts.name).to_s opts.namespace = [opts.namespace] unless opts.namespace.is_a?(Array) return PLUGIN[opts.name] if PLUGIN[opts.name] die(%{Plugin "#{opts.name}" not found in "#{opts.folder}"}) unless Dir.exist?(opts.folder) PLUGIN[opts.name] ||= opts base = Pathname.new(opts.folder).join(opts.name, '.rb') if base.exist? require base.to_s else Dir.require_all(opts.folder) end PLUGIN[opts.name] end |
#loaded ⇒ Object
46 47 48 |
# File 'lib/lux/plugin/plugin.rb', line 46 def loaded PLUGIN.values end |
#plugins ⇒ Object
54 55 56 |
# File 'lib/lux/plugin/plugin.rb', line 54 def plugins PLUGIN end |