Sha256: 99508bf2d4f7b5e8bb42b42cc5fadbaaa1d9412b2b4f695d9adcce404d5cf0d8

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

module Discorb
  #
  # Represents a event handler.
  # This class shouldn't be instantiated directly.
  # Use {Client#on} instead.
  #
  class EventHandler
    # @return [Proc] the block to be called.
    attr_reader :block
    # @return [Symbol] the event id.
    attr_reader :id
    # @return [Hash] the event metadata.
    attr_reader :metadata
    # @return [Boolean] whether the event is once or not.
    attr_reader :once
    alias once? once

    def initialize(block, id, metadata)
      @block = block
      @id = id
      @once = metadata.fetch(:once, false)
      @metadata = metadata
      @rescue = nil
    end

    def inspect
      "#<#{self.class} @id=#{@id}"
    end

    #
    # Calls the block associated with the event.
    #
    def call(...)
      @block.call(...)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
discorb-0.20.0 lib/discorb/event_handler.rb