Sha256: 0183656228d90c75da84fd18e2e0fe1fbf810fdb61678b7def8765e2bdff25f4

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require_relative "terminalwire/version"

require 'socket'
require 'forwardable'
require 'uri'
require 'zeitwerk'

require 'async'
require 'async/http/endpoint'
require 'async/websocket/client'
require 'async/websocket/adapters/rack'

module Terminalwire
  class Error < StandardError; end

  Loader = Zeitwerk::Loader.for_gem.tap do |loader|
    loader.ignore("#{__dir__}/generators")
    loader.setup
  end

  module Resource
    class Base
      attr_reader :name, :adapter

      def initialize(name, adapter)
        @name = name.to_s
        @adapter = adapter
      end

      def connect; end
      def disconnect; end

      def fail(response, **data)
        respond(status: "failure", response:, **data)
      end

      def succeed(response, **data)
        respond(status: "success", response:, **data)
      end

      def self.protocol_key
        name.split("::").last.downcase
      end

      private

      def respond(**response)
        adapter.write(event: "resource", name: @name, **response)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
terminalwire-0.1.12 lib/terminalwire.rb
terminalwire-0.1.11 lib/terminalwire.rb
terminalwire-0.1.10 lib/terminalwire.rb
terminalwire-0.1.9 lib/terminalwire.rb
terminalwire-0.1.8 lib/terminalwire.rb
terminalwire-0.1.7 lib/terminalwire.rb
terminalwire-0.1.6 lib/terminalwire.rb
terminalwire-0.1.5 lib/terminalwire.rb
terminalwire-0.1.4 lib/terminalwire.rb
terminalwire-0.1.3 lib/terminalwire.rb
terminalwire-0.1.2 lib/terminalwire.rb