Class: NanDoc::CreateNanDocSite::StdErrListener
- Inherits:
-
Object
- Object
- NanDoc::CreateNanDocSite::StdErrListener
- Defined in:
- lib/nandoc/commands/create-nandoc-site.rb
Overview
Somehow legitimize these awful hacks with an entire class
Instance Method Summary collapse
-
#initialize(&block) ⇒ StdErrListener
constructor
A new instance of StdErrListener.
- #puts(*args) ⇒ Object (also: #write)
- #when(regex, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ StdErrListener
Returns a new instance of StdErrListener.
143 144 145 146 147 148 149 |
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 143 def initialize &block @prev = $stderr $stderr = self @expired = false @whens = [] block.call(self) end |
Instance Method Details
#puts(*args) ⇒ Object Also known as: write
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 153 def puts *args if @expired fail("hack failed when trying to write: #{str}") elsif args.size != 1 expire! $stderr.puts(*args) else found = @whens.detect{|x| x[:regex] =~ args.first} if found expire! found[:block].call else expire! $stderr.puts(*args) end end end |
#when(regex, &block) ⇒ Object
150 151 152 |
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 150 def when regex, &block @whens.push(:regex=>regex, :block=>block) end |