module Plug::ArrayFeeder
Uses an array of static messages as a datasource for opaque protocol messages. Useful as a generic blit-able loop
Attributes
close_at_end[RW]
feed[RW]
go_first[RW]
pos[RW]
squelch_exhausted[RW]
step[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Plug::Base::new
# File lib/rbkb/plug/plug.rb, line 169 def initialize(*args) super(*args) @pos ||= 0 @feed ||= [] raise "feed must be enumerable" unless Enumerable === @feed end
Public Instance Methods
connection_completed()
click to toggle source
Calls superclass method
Plug::Base#connection_completed
# File lib/rbkb/plug/plug.rb, line 185 def connection_completed peer=super() go if @go_first return peer end
feed_data(dst=plug_peer)
click to toggle source
# File lib/rbkb/plug/plug.rb, line 204 def feed_data(dst=plug_peer) unless dat=@feed[@pos] UI.log "** FEED EXHAUSTED" unless @squelch_exhausted return nil end dst.say dat.to_s, self if (@pos += 1) >= @feed.size and @close_at_end close_connection_after_writing end end
go()
click to toggle source
# File lib/rbkb/plug/plug.rb, line 178 def go if @go_first feed_data @go_first = false end end
say(dat, sender)
click to toggle source
Calls superclass method
Plug::Base#say
# File lib/rbkb/plug/plug.rb, line 192 def say(dat, sender) super(dat, sender) if @step EventMachine.defer( proc { UI.prompt ">> Hit [enter] to continue at #{@pos}:" }, proc {|x| feed_data } ) else feed_data end end