Class: CapistranoSentinel::InputStream

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano_sentinel/classes/input_stream.rb

Overview

class used to hook into the input stream

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(real_stdin, actor, stringio) ⇒ InputStream


15
16
17
18
19
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 15

def initialize(real_stdin, actor, stringio)
  self.real = real_stdin
  self.actor = actor
  self.stringio = stringio
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object


30
31
32
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 30

def method_missing(name, *args, &block)
  @real.send name, *args, &block
end

Instance Attribute Details

#actorObject

Returns the value of attribute actor


13
14
15
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 13

def actor
  @actor
end

#realObject

Returns the value of attribute real


13
14
15
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 13

def real
  @real
end

#stringioObject

Returns the value of attribute stringio


13
14
15
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 13

def stringio
  @stringio
end

Class Method Details

.hook(actor, stringio) ⇒ Object


4
5
6
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 4

def self.hook(actor, stringio)
  $stdin = new($stdin, actor, stringio)
end

.unhookObject


8
9
10
11
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 8

def self.unhook
  $stdin.finish if $stdin.is_a? CapistranoSentinel::InputStream
  $stdin = STDIN
end

Instance Method Details

#finishObject


27
28
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 27

def finish
end

#gets(*_args) ⇒ Object


21
22
23
24
25
# File 'lib/capistrano_sentinel/classes/input_stream.rb', line 21

def gets(*_args)
  @stringio.rewind
  data = @stringio.read
  @actor.user_prompt_needed?(data)
end