Class: LeanWeb::App
- Inherits:
-
Object
- Object
- LeanWeb::App
- Defined in:
- lib/leanweb/app.rb
Overview
App resolves and builds static files from routes.
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
-
#build_static ⇒ Object
Build static routes to files.
-
#call(env) ⇒ Object
Entry point for dynamic routes (Rack).
-
#initialize(routes) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(routes) ⇒ App
Returns a new instance of App.
18 19 20 |
# File 'lib/leanweb/app.rb', line 18 def initialize(routes) @routes = routes end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
15 16 17 |
# File 'lib/leanweb/app.rb', line 15 def routes @routes end |
Instance Method Details
#build_static ⇒ Object
Build static routes to files.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/leanweb/app.rb', line 35 def build_static @routes.each do |route| route = Route.new(**route) next unless route.static begin route.static.each{ |seed| route.build(route.seed_path(seed)) } rescue NoMethodError route.build end end end |
#call(env) ⇒ Object
Entry point for dynamic routes (Rack).
25 26 27 28 29 30 31 32 |
# File 'lib/leanweb/app.rb', line 25 def call(env) request = Rack::Request.new(env) route = find_route(request) route = Route.new(**route) unless route.nil? return [404, {}, ['Not found']] unless route&.available? route.respond(request) end |