Class: RubyHome::HAP::ServerHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/hap/server_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration:) ⇒ ServerHandler

Returns a new instance of ServerHandler.



13
14
15
# File 'lib/ruby_home/hap/server_handler.rb', line 13

def initialize(configuration: )
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



60
61
62
# File 'lib/ruby_home/hap/server_handler.rb', line 60

def configuration
  @configuration
end

Instance Method Details

#bind_addressObject



52
53
54
# File 'lib/ruby_home/hap/server_handler.rb', line 52

def bind_address
  configuration.host
end

#portObject



56
57
58
# File 'lib/ruby_home/hap/server_handler.rb', line 56

def port
  configuration.port
end

#runObject



17
18
19
# File 'lib/ruby_home/hap/server_handler.rb', line 17

def run
  server.start
end

#serverObject



25
26
27
28
29
30
# File 'lib/ruby_home/hap/server_handler.rb', line 25

def server
  @server ||= RackHandler.run(
    HTTP::Application.rack_builder,
    server_options
  )
end

#server_loggerObject



42
43
44
45
46
47
48
49
50
# File 'lib/ruby_home/hap/server_handler.rb', line 42

def server_logger
  if ENV['DEBUG'] == 'debug'
    WEBrick::Log::new(STDOUT, WEBrick::BasicLog::DEBUG)
  elsif ENV['DEBUG'] == 'info'
    WEBrick::Log::new(STDOUT, WEBrick::BasicLog::INFO)
  else
    WEBrick::Log::new("/dev/null", WEBrick::BasicLog::WARN)
  end
end

#server_optionsObject



32
33
34
35
36
37
38
39
40
# File 'lib/ruby_home/hap/server_handler.rb', line 32

def server_options
  {
    Port: port,
    Host: bind_address,
    ServerSoftware: 'RubyHome',
    Logger: server_logger,
    AccessLog: []
  }
end

#shutdownObject



21
22
23
# File 'lib/ruby_home/hap/server_handler.rb', line 21

def shutdown
  server.shutdown
end