Module: WrapIO
- Defined in:
- lib/wrapio.rb,
lib/wrapio/fake.rb,
lib/wrapio/capture.rb,
lib/wrapio/version.rb
Overview
A small module that allows performs both capturing output from STDOUT and faking input to STDIN.
Defined Under Namespace
Constant Summary collapse
- VERSION =
The curent version
"0.0.1"
- @@debug =
Returns
true
if debugging is enabled. false
- @@delimiters =
Internal markers for debug logging
{ :input => 'Fake#gets', :output => 'Capture#output' }
- @@default_input =
Returns the default input if not specified in WrapIO#of.
''
Instance Attribute Summary collapse
-
#debug ⇒ Boolean
true
if debugging is enabled. -
#default_input ⇒ String, Array
The default input if not specified in WrapIO#of.
Class Method Summary collapse
-
.debug ⇒ Boolean
true
if debugging is enabled. -
.debug=(value) ⇒ Object
Enable or disables debugging.
-
.default_input ⇒ String, Array
The default input if not specified in WrapIO#of.
-
.default_input=(value) ⇒ Object
Set the default input if not specified in WrapIO#of.
-
.log(data, type, index = nil) ⇒ Object
Used within module classes to output debug data.
-
.of(input = nil) { ... } ⇒ String
The main action of the
WrapIO
module As the semantic reading of the module name and function implies.
Instance Attribute Details
#debug ⇒ Boolean
Returns true
if debugging is enabled.
16 |
# File 'lib/wrapio.rb', line 16 @@debug = false |
#default_input ⇒ String, Array
Returns the default input if not specified in WrapIO#of.
30 |
# File 'lib/wrapio.rb', line 30 @@default_input = '' |
Class Method Details
.debug ⇒ Boolean
Returns true
if debugging is enabled.
35 36 37 |
# File 'lib/wrapio.rb', line 35 def self.debug @@debug end |
.debug=(value) ⇒ Object
Enable or disables debugging
43 44 45 |
# File 'lib/wrapio.rb', line 43 def self.debug=(value) @@debug = value end |
.default_input ⇒ String, Array
Returns the default input if not specified in WrapIO#of.
50 51 52 |
# File 'lib/wrapio.rb', line 50 def self.default_input @@default_input end |
.default_input=(value) ⇒ Object
Set the default input if not specified in WrapIO#of
58 59 60 |
# File 'lib/wrapio.rb', line 58 def self.default_input=(value) @@default_input = value end |
.log(data, type, index = nil) ⇒ Object
Used within module classes to output debug data
88 89 90 |
# File 'lib/wrapio.rb', line 88 def self.log(data, type, index=nil) puts delimit(data, type, index.to_s) end |
.of(input = nil) { ... } ⇒ String
The main action of the WrapIO
module As the semantic reading of the module name and function implies. It wraps the input and output of the given block, making the input passable as a parameter and the output accessible as a return value.
72 73 74 75 76 77 78 79 |
# File 'lib/wrapio.rb', line 72 def self.of(input=nil) input = WrapIO.default_input.map{|i| i.to_s.dup} unless input Capture.output do Fake.input(input) do yield end end end |