Class: Lively::Application

Inherits:
Protocol::HTTP::Middleware
  • Object
show all
Defined in:
lib/lively/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(delegate, resolver: self.class.resolver) ⇒ Application

Returns a new instance of Application.



30
31
32
33
34
# File 'lib/lively/application.rb', line 30

def initialize(delegate, resolver: self.class.resolver)
  super(delegate)
  
  @resolver = resolver
end

Instance Method Details

#bodyObject



44
45
46
# File 'lib/lively/application.rb', line 44

def body
  "Hello World"
end

#call(request) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/lively/application.rb', line 52

def call(request)
  if request.path == '/live'
    return Async::WebSocket::Adapters::HTTP.open(request, &self.method(:live)) || Protocol::HTTP::Response[400]
  else
    return Protocol::HTTP::Response[200, [], [self.index.call]]
  end
end

#indexObject



48
49
50
# File 'lib/lively/application.rb', line 48

def index
  Pages::Index.new(title: self.title, body: self.body)
end

#live(connection) ⇒ Object



36
37
38
# File 'lib/lively/application.rb', line 36

def live(connection)
  Live::Page.new(@resolver).run(connection)
end

#titleObject



40
41
42
# File 'lib/lively/application.rb', line 40

def title
  self.class.name
end