Module: Plug::ArrayFeeder

Includes:
Base
Defined in:
lib/rbkb/plug/plug.rb

Overview

Uses an array of static messages as a datasource for opaque protocol messages. Useful as a generic blit-able loop

Instance Attribute Summary collapse

Attributes included from Base

#kind, #no_stop_on_unbind, #peers, #tls, #tls_opts, #transport

Instance Method Summary collapse

Methods included from Base

#name, #plug_peer, #plug_receive, #post_init, #receive_data, #unbind

Instance Attribute Details

#close_at_endObject

Returns the value of attribute close_at_end.



166
167
168
# File 'lib/rbkb/plug/plug.rb', line 166

def close_at_end
  @close_at_end
end

#feedObject

Returns the value of attribute feed.



166
167
168
# File 'lib/rbkb/plug/plug.rb', line 166

def feed
  @feed
end

#go_firstObject

Returns the value of attribute go_first.



166
167
168
# File 'lib/rbkb/plug/plug.rb', line 166

def go_first
  @go_first
end

#posObject

Returns the value of attribute pos.



166
167
168
# File 'lib/rbkb/plug/plug.rb', line 166

def pos
  @pos
end

#squelch_exhaustedObject

Returns the value of attribute squelch_exhausted.



166
167
168
# File 'lib/rbkb/plug/plug.rb', line 166

def squelch_exhausted
  @squelch_exhausted
end

#stepObject

Returns the value of attribute step.



166
167
168
# File 'lib/rbkb/plug/plug.rb', line 166

def step
  @step
end

Instance Method Details

#connection_completedObject



185
186
187
188
189
# 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) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
# 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

#goObject



178
179
180
181
182
183
# File 'lib/rbkb/plug/plug.rb', line 178

def go
  if @go_first
    feed_data
    @go_first = false
  end
end

#initialize(*args) ⇒ Object



169
170
171
172
173
174
175
176
# 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

#say(dat, sender) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
# 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