Class: Spinoff::Server::Generic
- Inherits:
-
Object
- Object
- Spinoff::Server::Generic
- Defined in:
- lib/spinoff/server/generic.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
- #accept_loop ⇒ Object
- #disconnect_client(client) ⇒ Object
- #init_script ⇒ Object
-
#initialize(config) ⇒ Generic
constructor
A new instance of Generic.
- #start ⇒ Object
Constructor Details
#initialize(config) ⇒ Generic
Returns a new instance of Generic.
13 14 15 16 |
# File 'lib/spinoff/server/generic.rb', line 13 def initialize(config) @config = config @socket = create_socket end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/spinoff/server/generic.rb', line 11 def config @config end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
11 12 13 |
# File 'lib/spinoff/server/generic.rb', line 11 def socket @socket end |
Class Method Details
.start(config) ⇒ Object
7 8 9 |
# File 'lib/spinoff/server/generic.rb', line 7 def self.start(config) new(config).start end |
Instance Method Details
#accept_loop ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/spinoff/server/generic.rb', line 26 def accept_loop loop do connection = socket.accept files = connection.gets.chomp.split(File::PATH_SEPARATOR) disconnect_client(connection) yield(files) end end |
#disconnect_client(client) ⇒ Object
36 37 38 39 |
# File 'lib/spinoff/server/generic.rb', line 36 def disconnect_client(client) client.print("\0") client.close end |
#init_script ⇒ Object
18 19 20 |
# File 'lib/spinoff/server/generic.rb', line 18 def init_script File.(@config.fetch(:init_script, File.join(Dir.pwd, 'spinoff.rb'))) end |
#start ⇒ Object
22 23 24 |
# File 'lib/spinoff/server/generic.rb', line 22 def start raise "#{self.class}#start not implemented." end |