Sha256: cd7d3ad2cc5a6679106e69c16055aa0c1e22557a6641b821cd254335623f669b

Contents?: true

Size: 892 Bytes

Versions: 11

Compression:

Stored size: 892 Bytes

Contents

require "open3"
require "io/wait"

module Textbringer
  Command = Struct.new(:name, :block, :doc)

  module Commands
    include Utils

    @command_table = {}

    def self.list
      @command_table.keys
    end

    def self.command_table
      @command_table
    end

    def self.[](name)
      @command_table[name.intern]
    end

    def define_command(name, doc: "No documentation", &block)
      name = name.intern
      Commands.send(:define_method, name, &block)
      Commands.send(:module_function, name)
      Commands.command_table[name] = Command.new(name, block, doc)
      name
    end
    module_function :define_command

    def undefine_command(name)
      name = name.intern
      if Commands.command_table.key?(name)
        Commands.send(:undef_method, name)
        Commands.command_table.delete(name)
      end
    end
    module_function :undefine_command
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
textbringer-1.4.1 lib/textbringer/commands.rb
textbringer-1.3.0 lib/textbringer/commands.rb
textbringer-1.2.0 lib/textbringer/commands.rb
textbringer-1.1.2 lib/textbringer/commands.rb
textbringer-1.1.1 lib/textbringer/commands.rb
textbringer-1.1.0 lib/textbringer/commands.rb
textbringer-1.0.9 lib/textbringer/commands.rb
textbringer-1.0.4 lib/textbringer/commands.rb
textbringer-1.0.3 lib/textbringer/commands.rb
textbringer-1.0.2 lib/textbringer/commands.rb
textbringer-1.0.1 lib/textbringer/commands.rb