Sha256: 3f7d69ec5096d76619ea5c77041d22c9daba1daaed4b9b3debe61784aca34b7a

Contents?: true

Size: 923 Bytes

Versions: 12

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

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

12 entries across 12 versions & 1 rubygems

Version Path
textbringer-1.0.0 lib/textbringer/commands.rb
textbringer-0.3.2 lib/textbringer/commands.rb
textbringer-0.3.1 lib/textbringer/commands.rb
textbringer-0.3.0 lib/textbringer/commands.rb
textbringer-0.2.9 lib/textbringer/commands.rb
textbringer-0.2.8 lib/textbringer/commands.rb
textbringer-0.2.7 lib/textbringer/commands.rb
textbringer-0.2.6 lib/textbringer/commands.rb
textbringer-0.2.4 lib/textbringer/commands.rb
textbringer-0.2.5 lib/textbringer/commands.rb
textbringer-0.2.3 lib/textbringer/commands.rb
textbringer-0.2.2 lib/textbringer/commands.rb