Class: Lipa::Web::Application

Inherits:
Object
  • Object
show all
Includes:
Response
Defined in:
lib/lipa/web/application.rb

Overview

Rack application

Instance Method Summary collapse

Methods included from Response

#respond

Constructor Details

#initialize(root) ⇒ Application

Init app

Parameters:

  • root (Lipa::Root)

    Lipa structure



39
40
41
# File 'lib/lipa/web/application.rb', line 39

def initialize(root)
  @root = root
end

Instance Method Details

#call(env) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lipa/web/application.rb', line 43

def call(env)
  path, format = env['PATH_INFO'].split(".")
  node = @root[path]
  if node
    respond(node, format)
  else
    static_path = File.join(@root.static_folder, env['PATH_INFO'])
    if File.exist?(static_path)
      [ 200, { "Content-Type" => "text/#{format}" }, [File.read(static_path)]]
    else
      [ 500,
        
        {"Content-Type" => "text/html"}, 
        [
          "Node is not existence"
        ]
      ]
    end
  end
end