Class: RemoteRuby::CachingAdapter

Inherits:
ConnectionAdapter show all
Defined in:
lib/remote_ruby/connection_adapter/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

Returns a new instance of CachingAdapter.



7
8
9
10
# File 'lib/remote_ruby/connection_adapter/caching_adapter.rb', line 7

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

Instance Method Details

#connection_nameObject



12
13
14
# File 'lib/remote_ruby/connection_adapter/caching_adapter.rb', line 12

def connection_name
  adapter.connection_name
end

#open(code) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/remote_ruby/connection_adapter/caching_adapter.rb', line 16

def open(code)
  with_cache do |stdout_cache, stderr_cache|
    adapter.open(code) do |stdout, stderr|
      yield ::RemoteRuby::StreamCacher.new(stdout, stdout_cache),
      ::RemoteRuby::StreamCacher.new(stderr, stderr_cache)
    end
  end
end