Module: Ego

Defined in:
lib/ego.rb,
lib/ego/robot.rb,
lib/ego/plugin.rb,
lib/ego/runner.rb,
lib/ego/handler.rb,
lib/ego/options.rb,
lib/ego/printer.rb,
lib/ego/version.rb,
lib/ego/capability.rb,
lib/ego/filesystem.rb,
lib/ego/robot_error.rb,
lib/ego/plugin_helper.rb

Defined Under Namespace

Modules: Filesystem, Printer Classes: Capability, Handler, Options, Plugin, PluginHelper, Robot, RobotError, Runner

Constant Summary collapse

VERSION =

Gem version

'0.6.0'

Class Method Summary collapse

Class Method Details

.plugin(name = nil, &body) ⇒ Plugin

Public interface for defining a plug-in.

Ego looks for user-defined plug-ins in $XDG_CONFIG_HOME/ego/plugins/ (that's ~/.config/ego/plugins/ by default), and registers them automatically at runtime. Each plug-in goes in it's own file with an .rb extension (e.g., ~/.config/ego/plugins/my_plugin.rb).

Be careful---ego will execute any Ruby scripts in this directory indiscriminately.

Examples:

Create and register a new plug-in

# ~/.config/ego/plugins/echo.rb
Ego.plugin do |robot|
  robot.can 'repeat what you say'

  robot.on /^say (?<input>.+)/i do |input|
    say input
  end
end

Parameters:

  • name (String, nil) (defaults to: nil)

    the plug-in name (uses plug-in file's basename if given nil)

  • body

    the plug-in body

Returns:

  • (Plugin)

    the instantiated plug-in

See Also:



35
36
37
38
39
40
41
# File 'lib/ego.rb', line 35

def self.plugin(name = nil, &body)
  path = caller_locations(1, 1)[0].absolute_path
  name ||= File.basename(path, '.*')
  builtin = path.start_with?(__dir__)

  Plugin.register(name, body, builtin: builtin)
end