Class: Rucoa::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rucoa/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io_in: ::StringIO.new, io_log: ::StringIO.new, io_out: ::StringIO.new) ⇒ Server

Returns a new instance of Server.

Parameters:

  • io_log (IO) (defaults to: ::StringIO.new)
  • io_in (IO) (defaults to: ::StringIO.new)
  • io_out (IO) (defaults to: ::StringIO.new)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rucoa/server.rb', line 46

def initialize(
  io_in: ::StringIO.new,
  io_log: ::StringIO.new,
  io_out: ::StringIO.new
)
  @logger = ::Logger.new(io_log)
  @logger.level = ::Logger::DEBUG
  @reader = MessageReader.new(io_in)
  @writer = MessageWriter.new(io_out)

  @client_response_handlers = {}
  @configuration = Configuration.new
  @server_request_id = 0
  @shutting_down = false
  @source_store = SourceStore.new

  @definition_store = DefinitionStore.new
  @definition_store.bulk_add(DefinitionArchiver.load)
end

Instance Attribute Details

#configurationRucoa::Configuration (readonly)



35
36
37
# File 'lib/rucoa/server.rb', line 35

def configuration
  @configuration
end

#definition_storeRucoa::DefinitionStore (readonly)



38
39
40
# File 'lib/rucoa/server.rb', line 38

def definition_store
  @definition_store
end

#shutting_downBoolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/rucoa/server.rb', line 32

def shutting_down
  @shutting_down
end

#source_storeRucoa::SourceStore (readonly)

Returns:



41
42
43
# File 'lib/rucoa/server.rb', line 41

def source_store
  @source_store
end

Instance Method Details

#finishvoid

This method returns an undefined value.



67
68
69
# File 'lib/rucoa/server.rb', line 67

def finish
  exit(0)
end

#responsesArray<Hash>

Note:

This method is for testing.

Returns:

  • (Array<Hash>)


73
74
75
76
77
# File 'lib/rucoa/server.rb', line 73

def responses
  io = @writer.io
  io.rewind
  MessageReader.new(io).read.to_a
end

#startvoid

This method returns an undefined value.



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rucoa/server.rb', line 80

def start
  @reader.read do |message|
    debug do
      {
        kind: :read,
        message: message
      }
    end
    handle(message)
  end
end

#write(message) {|response| ... } ⇒ void

This method returns an undefined value.

Parameters:

  • message (Hash)

Yield Parameters:

  • response (Hash)


95
96
97
98
99
100
101
102
103
104
# File 'lib/rucoa/server.rb', line 95

def write(
  message,
  &block
)
  if block
    write_server_request(message, &block)
  else
    write_server_response(message)
  end
end