module Wpxf::Cli::Modules

Methods for handling module loading and searching.

Attributes

context_stack[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/wpxf/cli/modules.rb, line 7
def initialize
  super
  self.context_stack = []
end

Public Instance Methods

back() click to toggle source
# File lib/wpxf/cli/modules.rb, line 16
def back
  context_stack.pop
  context.module.active_workspace = active_workspace if context

  refresh_autocomplete_options
end
context() click to toggle source
# File lib/wpxf/cli/modules.rb, line 12
def context
  context_stack.last
end
module_name_from_class(klass) click to toggle source
# File lib/wpxf/cli/modules.rb, line 57
def module_name_from_class(klass)
  klass.new.module_name
end
print_module_table(modules) click to toggle source
reload() click to toggle source
# File lib/wpxf/cli/modules.rb, line 23
def reload
  return unless module_loaded?(false)

  begin
    mod = context.reload
    mod.event_emitter.subscribe(self)
    mod.active_workspace = active_workspace
    print_good "Reloaded module: #{mod}"
  rescue StandardError => e
    print_bad "Failed to reload module: #{e}"
    return
  end

  apply_global_options(mod)
end
reset_context_stack() click to toggle source
# File lib/wpxf/cli/modules.rb, line 86
def reset_context_stack
  self.context_stack = []
  setup_auto_complete
end
search_modules(args) click to toggle source
# File lib/wpxf/cli/modules.rb, line 61
def search_modules(args)
  modules = Wpxf::Models::Module.where(Sequel.ilike(:name, "%#{args.join(' ')}%"))
  modules.map { |m| { path: m.path, title: m.name } }
end
use(module_path) click to toggle source
# File lib/wpxf/cli/modules.rb, line 39
def use(module_path)
  context = Context.new
  begin
    mod = context.load_module(module_path)
    mod.event_emitter.subscribe(self)
    mod.active_workspace = active_workspace
    print_good "Loaded module: #{mod}"
    mod.emit_usage_info
    context_stack.push(context)
  rescue StandardError => e
    print_bad "Failed to load module: #{e}"
    return
  end

  apply_global_options(mod)
  refresh_autocomplete_options
end