Class: RelinePac::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/reline_pac/config.rb

Overview

Config manages Reline keybindings and package installation.

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
# File 'lib/reline_pac/config.rb', line 6

def initialize
  Packages.install_all
end

Instance Method Details

#add_keybind(key, method) ⇒ Object

Add a keybinding that invokes the given LineEditor method symbol.

Parameters:

  • key (String)

    a string such as "\C-r"

  • method (Symbol)

    the LineEditor method to invoke



26
27
28
29
# File 'lib/reline_pac/config.rb', line 26

def add_keybind(key, method)
  key_bytes = key.bytes
  reline_config.add_default_key_binding(key_bytes, method)
end

#add_package(method_name) { ... } ⇒ Object

Add a custom package (method) to Reline::LineEditor.

Parameters:

  • method_name (Symbol)

    the method name to add

Yields:

  • a block that defines the method body; receives _key as first argument

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
# File 'lib/reline_pac/config.rb', line 13

def add_package(method_name, &block)
  raise ArgumentError, 'add_package requires a block to define the package method body' unless block_given?

  Packages::Custom.module_eval do
    define_method(method_name, &block)
  end

  Reline::LineEditor.prepend(Packages::Custom) unless Reline::LineEditor.ancestors.include?(Packages::Custom)
end