Class: SQLiteSweep::SourceStream
- Inherits:
-
Object
- Object
- SQLiteSweep::SourceStream
- Defined in:
- lib/sqlitesweep/source_stream.rb
Overview
Reads database URIs from a shell command, one per line.
The command is run via IO.popen and its stdout is read line-by-line. Each non-empty line is parsed into a DatabaseURI. Blank lines are skipped.
The command can be anything: a simple cat, a ‘rails runner` invocation, a script that queries an API, etc. Whatever it is, it must output one database URI per line to stdout.
Instance Method Summary collapse
-
#each {|uri| ... } ⇒ Object
Yields each DatabaseURI from the source command’s output.
-
#initialize(command) ⇒ SourceStream
constructor
A new instance of SourceStream.
Constructor Details
#initialize(command) ⇒ SourceStream
Returns a new instance of SourceStream.
19 20 21 |
# File 'lib/sqlitesweep/source_stream.rb', line 19 def initialize(command) @command = command end |
Instance Method Details
#each {|uri| ... } ⇒ Object
Yields each DatabaseURI from the source command’s output. Returns an Enumerator if no block is given.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sqlitesweep/source_stream.rb', line 28 def each(&block) return enum_for(:each) unless block_given? IO.popen(@command, "r") do |io| io.each_line do |line| line = line.strip next if line.empty? yield DatabaseURI.new(line) end end unless $?.success? raise SourceError, "Source command exited with status #{$?.exitstatus}: #{@command}" end end |