Class: RemoteRuby::TextModeAdapter
- Inherits:
-
ConnectionAdapter
- Object
- ConnectionAdapter
- RemoteRuby::TextModeAdapter
- Defined in:
- lib/remote_ruby/text_mode_adapter.rb
Overview
Decorates a connection adapter. Reads the output streams line-by-line and prefixes them according to the settings.
Constant Summary collapse
- DEFAULT_SETTINGS =
{ stdout_mode: { color: :green, mode: :italic }, stderr_mode: { color: :red, mode: :italic }, cache_mode: { color: :blue, mode: :bold }, cache_prefix: '[C] ' }.freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#cache_mode ⇒ Object
readonly
Returns the value of attribute cache_mode.
-
#cache_prefix ⇒ Object
readonly
Returns the value of attribute cache_prefix.
-
#stderr_mode ⇒ Object
readonly
Returns the value of attribute stderr_mode.
-
#stderr_prefix ⇒ Object
readonly
Returns the value of attribute stderr_prefix.
-
#stdout_mode ⇒ Object
readonly
Returns the value of attribute stdout_mode.
-
#stdout_prefix ⇒ Object
readonly
Returns the value of attribute stdout_prefix.
Instance Method Summary collapse
-
#initialize(adapter, **params) ⇒ TextModeAdapter
constructor
A new instance of TextModeAdapter.
- #open(code, stdin, stdout, stderr) ⇒ Object
Methods inherited from ConnectionAdapter
Constructor Details
#initialize(adapter, **params) ⇒ TextModeAdapter
Returns a new instance of TextModeAdapter.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 20 def initialize(adapter, **params) super() @adapter = adapter @stdout_prefix = params[:stdout_prefix] @stderr_prefix = params[:stderr_prefix] @cache_prefix = params[:cache_prefix] @stdout_mode = params[:stdout_mode] @stderr_mode = params[:stderr_mode] @cache_mode = params[:cache_mode] end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
17 18 19 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 17 def adapter @adapter end |
#cache_mode ⇒ Object (readonly)
Returns the value of attribute cache_mode.
17 18 19 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 17 def cache_mode @cache_mode end |
#cache_prefix ⇒ Object (readonly)
Returns the value of attribute cache_prefix.
17 18 19 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 17 def cache_prefix @cache_prefix end |
#stderr_mode ⇒ Object (readonly)
Returns the value of attribute stderr_mode.
17 18 19 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 17 def stderr_mode @stderr_mode end |
#stderr_prefix ⇒ Object (readonly)
Returns the value of attribute stderr_prefix.
17 18 19 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 17 def stderr_prefix @stderr_prefix end |
#stdout_mode ⇒ Object (readonly)
Returns the value of attribute stdout_mode.
17 18 19 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 17 def stdout_mode @stdout_mode end |
#stdout_prefix ⇒ Object (readonly)
Returns the value of attribute stdout_prefix.
17 18 19 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 17 def stdout_prefix @stdout_prefix end |
Instance Method Details
#open(code, stdin, stdout, stderr) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/remote_ruby/text_mode_adapter.rb', line 31 def open(code, stdin, stdout, stderr) stdout_pref = "#{cache_prefix_string}#{stdout_prefix_string}" stderr_pref = "#{cache_prefix_string}#{stderr_prefix_string}" stdout = StreamPrefixer.new(stdout, stdout_pref) unless stdout_prefix_string.nil? stderr = StreamPrefixer.new(stderr, stderr_pref) unless stderr_prefix_string.nil? adapter.open(code, stdin, stdout, stderr) end |