Class: Cat::Server

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

Constant Summary collapse

ACCEPT_PATH =
["/", "/skin.css"]

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cat/server.rb', line 5

def self.call(env)
  return [404, {"Content-Type" => "text/plain"}, ["No cats found"]] unless ACCEPT_PATH.include?(env['PATH_INFO'])

  @last_update ||= Time.now
  @cat_update = File.mtime(Cat.config_file)
  if @cat_update > @last_update
    load Cat.config_file
    @last_update = @cat_update
  end

  case env['PATH_INFO']
  when "/" then response_skeleton
  when "/skin.css" then response_skin
  end
end

.response_skeletonObject



21
22
23
24
25
26
27
# File 'lib/cat/server.rb', line 21

def self.response_skeleton
  [
    200,
    {"Content-Type" => "text/html"},
    [Cat.to_html]
  ]
end

.response_skinObject



29
30
31
32
33
34
35
# File 'lib/cat/server.rb', line 29

def self.response_skin
  [
    200,
    {"Content-Type" => "text/css"},
    [Cat.to_css]
  ]
end