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.



162
163
164
# File 'lib/rbkb/plug/plug.rb', line 162

def close_at_end
  @close_at_end
end

#feedObject

Returns the value of attribute feed.



162
163
164
# File 'lib/rbkb/plug/plug.rb', line 162

def feed
  @feed
end

#go_firstObject

Returns the value of attribute go_first.



162
163
164
# File 'lib/rbkb/plug/plug.rb', line 162

def go_first
  @go_first
end

#posObject

Returns the value of attribute pos.



162
163
164
# File 'lib/rbkb/plug/plug.rb', line 162

def pos
  @pos
end

#squelch_exhaustedObject

Returns the value of attribute squelch_exhausted.



162
163
164
# File 'lib/rbkb/plug/plug.rb', line 162

def squelch_exhausted
  @squelch_exhausted
end

#stepObject

Returns the value of attribute step.



162
163
164
# File 'lib/rbkb/plug/plug.rb', line 162

def step
  @step
end

Instance Method Details

#connection_completedObject



181
182
183
184
185
# File 'lib/rbkb/plug/plug.rb', line 181

def connection_completed
  peer=super()
  go if @go_first
  return peer
end

#feed_data(dst = plug_peer) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/rbkb/plug/plug.rb', line 200

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



174
175
176
177
178
179
# File 'lib/rbkb/plug/plug.rb', line 174

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

#initialize(*args) ⇒ Object



165
166
167
168
169
170
171
172
# File 'lib/rbkb/plug/plug.rb', line 165

def initialize(*args)
  super(*args)

  @pos ||= 0
  @feed ||= []

  raise "feed must be enumerable" unless Enumerable === @feed
end

#say(dat, sender) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/rbkb/plug/plug.rb', line 188

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