class Lugg::Runner
The runner defines the command line interface for Lugg
, using the other components and defining command line options and their implementations.
When creating a Runner
object, you pass it your option flags (typically `ARGV`). You can then apply its conditions to an IO object (typically `ARGF`).
@todo extract conditions into individual objects.
Attributes
filter[R]
Public Class Methods
new(flags = [], filter = Filter.new)
click to toggle source
# File lib/lugg/runner.rb, line 21 def initialize(flags = [], filter = Filter.new) @filter = filter reset options.parse!(flags) end
Public Instance Methods
add_clause(&block)
click to toggle source
# File lib/lugg/runner.rb, line 33 def add_clause(&block) if combine_clauses? prev_block = @last_block filter.use { |r| prev_block.call(r) && block.call(r) } reset else filter.use(&block) @last_block = block end end
combine_next()
click to toggle source
# File lib/lugg/runner.rb, line 44 def combine_next @combine = true end
run(io)
click to toggle source
# File lib/lugg/runner.rb, line 27 def run(io) filter.call(Streamer.new(io).records).each do |request| puts request.source end end
Private Instance Methods
combine_clauses?()
click to toggle source
# File lib/lugg/runner.rb, line 68 def combine_clauses? @combine && @last_block end
options()
click to toggle source
# File lib/lugg/runner.rb, line 50 def options @options ||= OptionParser.new do |o| o.banner = <<-EOS Usage: lugg [options] FILE Parses log entries from FILE or STDIN and uses [options] to control what is sent STDOUT. EOS o.separator '' Switch.apply_all(o, self) end end
reset()
click to toggle source
# File lib/lugg/runner.rb, line 63 def reset @combine = false @last_block = nil end