Sha256: 95982d192197771e86e0505e6ed87116bed35dcf59270f11528733f1e0cbcb76

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

require "fileutils"

module Terminalwire::Server
  class Context
    extend Forwardable

    attr_reader :stdout, :stdin, :stderr, :browser, :file, :directory, :storage_path

    def_delegators :@stdout, :puts, :print
    def_delegators :@stdin, :gets, :getpass

    def initialize(adapter:, entitlement:)
      @adapter = adapter

      @entitlement = entitlement
      @storage_path = Pathname.new(entitlement.fetch(:storage_path))

      @stdout = Resource::STDOUT.new("stdout", @adapter)
      @stdin = Resource::STDIN.new("stdin", @adapter)
      @stderr = Resource::STDERR.new("stderr", @adapter)
      @browser = Resource::Browser.new("browser", @adapter)
      @file = Resource::File.new("file", @adapter)
      @directory = Resource::Directory.new("directory", @adapter)

      if block_given?
        begin
          yield self
        ensure
          exit
        end
      end
    end

    def exit(status = 0)
      @adapter.write(event: "exit", status: status)
    end

    def close
      @adapter.close
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
terminalwire-0.1.17 lib/terminalwire/server/context.rb
terminalwire-0.1.16 lib/terminalwire/server/context.rb
terminalwire-0.1.15 lib/terminalwire/server/context.rb
terminalwire-0.1.14 lib/terminalwire/server/context.rb
terminalwire-0.1.13 lib/terminalwire/server/context.rb
terminalwire-0.1.12 lib/terminalwire/server/context.rb
terminalwire-0.1.11 lib/terminalwire/server/context.rb
terminalwire-0.1.10 lib/terminalwire/server/context.rb
terminalwire-0.1.9 lib/terminalwire/server/context.rb
terminalwire-0.1.8 lib/terminalwire/server/context.rb