Module: Clue::Streams
- Included in:
- Clue
- Defined in:
- lib/clue/streams.rb
Constant Summary collapse
- STREAMS_SYMBOLS =
{ :stdin => '<', :stdout => '>', :stderr => '2>' }
- RECOGNIZED_STREAMS =
STREAMS_SYMBOLS.keys
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#cli_streams ⇒ Object
Returns a string of streams suitable for cli use.
-
#init_streams(args = nil) ⇒ Object
Initialize streams ivars.
-
#set_stream(stream, value) ⇒ Object
set a stream.
-
#set_streams(streams) ⇒ Object
Add many arguemnts.
Instance Attribute Details
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
12 13 14 |
# File 'lib/clue/streams.rb', line 12 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
12 13 14 |
# File 'lib/clue/streams.rb', line 12 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
12 13 14 |
# File 'lib/clue/streams.rb', line 12 def stdout @stdout end |
Instance Method Details
#cli_streams ⇒ Object
Returns a string of streams suitable for cli use
32 33 34 35 36 37 38 39 40 |
# File 'lib/clue/streams.rb', line 32 def cli_streams ary = STREAMS_SYMBOLS.each_with_object([]) do |(key, value), memo| ivar = instance_variable_get "@#{key}" delimiter = self.config[:stream_delimiter] memo << "#{value} #{delimiter}#{ivar}#{delimiter}" if ivar end ary.join self.config[:between_streams] end |
#init_streams(args = nil) ⇒ Object
Initialize streams ivars
15 16 17 |
# File 'lib/clue/streams.rb', line 15 def init_streams(args = nil) set_streams(args.slice(*RECOGNIZED_STREAMS)) if args end |
#set_stream(stream, value) ⇒ Object
set a stream
20 21 22 |
# File 'lib/clue/streams.rb', line 20 def set_stream(stream, value) instance_variable_set "@#{stream.to_s}", value end |
#set_streams(streams) ⇒ Object
Add many arguemnts
25 26 27 28 29 |
# File 'lib/clue/streams.rb', line 25 def set_streams(streams) return unless streams && streams.kind_of?(Hash) streams.each { |stream, value| set_stream stream, value } end |