Class: RemoteRuby::CachingAdapter

Inherits:
ConnectionAdapter show all
Defined in:
lib/remote_ruby/caching_adapter.rb

Overview

An adapter decorator which extends the adapter passed in to its initializer to cache stdout and stderr to local filesystem

Instance Method Summary collapse

Constructor Details

#initialize(cache_path:, adapter:) ⇒ CachingAdapter



9
10
11
12
13
# File 'lib/remote_ruby/caching_adapter.rb', line 9

def initialize(cache_path:, adapter:)
  super
  @cache_path = cache_path
  @adapter = adapter
end

Instance Method Details

#connection_nameObject



28
29
30
# File 'lib/remote_ruby/caching_adapter.rb', line 28

def connection_name
  adapter.connection_name
end

#open(code, stdin, stdout, stderr) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/remote_ruby/caching_adapter.rb', line 15

def open(code, stdin, stdout, stderr)
  res = nil
  with_cache do |stdout_cache, stderr_cache, result_cache|
    tee_out = ::RemoteRuby::TeeWriter.new(stdout, stdout_cache)
    tee_err = ::RemoteRuby::TeeWriter.new(stderr, stderr_cache)

    res = adapter.open(code, stdin, tee_out, tee_err)
    result_cache.write(res)
  end

  res
end