Module: Lux::Config::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.
- #loaded ⇒ Object
- #plugins ⇒ Object
Instance Method Details
#folders(namespace = :main) ⇒ Object
get all folders in a namespace
57 58 59 60 61 62 63 |
# File 'lib/lux/config/lib/plugin.rb', line 57 def folders namespace=:main name = name.to_sym list = @plugins.values list.select { |it| it.namespace.include?(namespace) } list.map { |it| it.folder } end |
#get(name) ⇒ Object
40 41 42 |
# File 'lib/lux/config/lib/plugin.rb', line 40 def get name @plugins[name.to_s] || die('Plugin "%s" not loaded' % name) end |
#keys ⇒ Object
48 49 50 |
# File 'lib/lux/config/lib/plugin.rb', line 48 def keys @plugins.keys end |
#load(arg) ⇒ Object
load specific plugin Lux.plugin :foo Lux.plugin ‘foo/bar’ Lux.plugin.folders
10 11 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 |
# File 'lib/lux/config/lib/plugin.rb', line 10 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_opts name: String, folder: String, namespace: Symbol 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 @plugins[opts.name] if @plugins[opts.name] die(%{Plugin "#{opts.name}" not found in "#{opts.folder}"}) unless Dir.exist?(opts.folder) @plugins[opts.name] ||= opts base = Pathname.new(opts.folder).join(opts.name, '.rb') if base.exist? require base.to_s else Lux::Config.require_all(opts.folder) end @plugins[opts.name] end |
#loaded ⇒ Object
44 45 46 |
# File 'lib/lux/config/lib/plugin.rb', line 44 def loaded @plugins.values end |
#plugins ⇒ Object
52 53 54 |
# File 'lib/lux/config/lib/plugin.rb', line 52 def plugins @plugins end |