Sha256: 596a83c1e1966672afb9e9cca043a639a5b9b3a450e2c6e53bc601a484503295

Contents?: true

Size: 836 Bytes

Versions: 14

Compression:

Stored size: 836 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

14 entries across 14 versions & 1 rubygems

Version Path
discorb-0.19.0 lib/discorb/event_handler.rb
discorb-0.18.1 lib/discorb/event_handler.rb
discorb-0.18.0 lib/discorb/event_handler.rb
discorb-0.17.1 lib/discorb/event_handler.rb
discorb-0.17.0 lib/discorb/event_handler.rb
discorb-0.16.0 lib/discorb/event_handler.rb
discorb-0.15.1 lib/discorb/event_handler.rb
discorb-0.15.0 lib/discorb/event_handler.rb
discorb-0.14.0 lib/discorb/event_handler.rb
discorb-0.13.4 lib/discorb/event_handler.rb
discorb-0.13.3 lib/discorb/event_handler.rb
discorb-0.13.2 lib/discorb/event_handler.rb
discorb-0.13.1 lib/discorb/event_handler.rb
discorb-0.13.0 lib/discorb/event_handler.rb