class Cubic::Engine

Engine is what makes Cubic a Rack application.

Public Class Methods

call(env) click to toggle source
# File lib/cubic/engine.rb, line 8
def self.call(env)
  new(env).response.finish
end
new(env) click to toggle source
# File lib/cubic/engine.rb, line 12
def initialize(env)
  @request = Rack::Request.new(env)
end

Public Instance Methods

response() click to toggle source
# File lib/cubic/engine.rb, line 16
def response
  Application.load_app
  if search_routes
    Response.new render
  else
    Response.new(status_404)
  end
end

Private Instance Methods

merge_params() click to toggle source

Combines the params generated when checking routes with the params given by Rack::Request.

# File lib/cubic/engine.rb, line 33
def merge_params
  @request.params.merge(Router.params)
end
render() click to toggle source

Render a view.

# File lib/cubic/engine.rb, line 38
def render
  Render.new(merge_params, @content[:block]).template
end
search_routes() click to toggle source

Checks if path given by Rack::Request matches any defined routes.

# File lib/cubic/engine.rb, line 44
def search_routes
  route = Router.search @request.request_method, @request.path
  route ? @content = route : nil
end
status_404() click to toggle source
# File lib/cubic/engine.rb, line 27
def status_404
  { body: 'not found', status: 404 }
end