From 6ea60c1074ca02072f027121a493cb0c67111278 Mon Sep 17 00:00:00 2001 From: timbynce Date: Fri, 26 Aug 2022 22:55:51 +0300 Subject: [PATCH 1/5] without logger --- .byebug_history | 229 ++++++++++++++++++++++++++++ app/controllers/tests_controller.rb | 8 +- app/views/tests/index.html.erb | 9 +- app/views/tests/show.html.erb | 10 ++ config/routes.rb | 3 +- lib/simpler/application.rb | 8 + lib/simpler/controller.rb | 23 ++- lib/simpler/router.rb | 1 - lib/simpler/router/route.rb | 22 ++- 9 files changed, 303 insertions(+), 10 deletions(-) create mode 100644 .byebug_history create mode 100644 app/views/tests/show.html.erb diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 00000000..9e072068 --- /dev/null +++ b/.byebug_history @@ -0,0 +1,229 @@ +c +route_path +user_path +c +@params +route_path +exit +route_path +user_path +user_path.match?(route_path) +@path +exit +"/tests/1".match(/\/tests\/(\w+)\Z/) +"/tests/1".match?(/\/tests\/(\w+)\Z/) +"/tests/1".match?(/\/tests\/(\w+)/) +"/tests/1".match?(/\/tests\/(\w+)/Z) +/tests/1.match?(/\/tests\/(\w+)/) +"/tests/1".match?(/\/tests\/(\w+)/) +"/tests/1".match?("/\/tests\/(\w+)/") +"/tests/1".match? "/\/tests\/(\w+)/" +"/tests/1".match?('/\/tests\/(\w+)/') +route_path +"/tests/1".match?(route_path) +"/tests/1".match?("/\/tests\/(\w+)/") +user_path.match?(route_path) +route_path +user_path +c +route_path +user_path +@path +exit +Hash[keys.captures.zip(values.captures)] +Hash[*keys.captures.zip(values.captures)] +keys.captures.zip(values.captures) +values.captures +keys.captures +keys.captures.zip(values.captures) +keys.captures +keys +keys.names +@path +c +@path +exit +keys +values +route_path +user_path +user_path.match?(route_path) +@path +exit +values +keys +@path +c +@path +path +c +keys +values +c +keys +exit +route_path +@path +route_path +keys +route_path +c +route_path +values +route_path +c +@router +@router.route_for(env) +c +@routes.find { |route| route.match?(method, path) } +c +route +c +@routes.find { |route| route.match?(method, path) } +path +@routes +c +@router.route_for(env) +env +@router +route +c +@method == method && correct_path?(path) +c +@method == method && correct_path?(path) +correct_path?(path) +c +@path +path +correct_path?(path) +c +correct_path?(path) +exit +c +correct_path?(path) +@method == method +@method +c +@routes.find { |route| route.match?(method, path) } +c +route +c +@params +c +@path +c +@path +path +exit +@params +c +route +c +@path +path +c +@path +user_path +route_path +@params +c +exit +user_path +path +@params +params +c +@path +path +c +@path +path +exit +@path +path +@params +exit +path.each { |string| @params.push(string) if string.start_with?(':') } +path = @path.split('/') +@params +path.each { |string| @params.push(string) if string.start_with?(':') } +params(path) +path = path.split('/') +path +@path +c +@path +exit +c +@path +c +@path +path +exit +correct_params_count?(path) +@path +path +c +@path +path +exit +@path +path +@path.split('/').size +path.split('/').size +correct_params_count?(path) +exit +@method +@path +path +exit +method +@routes +exit +@routes +@path +@routes +@route +exit +@routes +env +env['PATH_INFO'] +@request +@path +exit +route.map { |param| param?(param) ? '[[:alnum:]]' :param } +route = params(@path) +params(@path) +@path +exit +@routes +exit +env['PATH_INFO'] +env['PATH_INFO']) +env +exit +@path +exctract_params(@path) +exit +correct_path +correct_path?(path) +path +exit +path +method +@routes[2] +@routes[0] +@routes[1] +@routes.find { |route| route.match?(method, path) +@routes +route +exit +@method +method +path +exit +@path +exit +@params +@request.env['PATH_INFO'].split('/')[2] +@request.env['PATH_INFO'] diff --git a/app/controllers/tests_controller.rb b/app/controllers/tests_controller.rb index 1526a689..422f8cc3 100644 --- a/app/controllers/tests_controller.rb +++ b/app/controllers/tests_controller.rb @@ -1,7 +1,13 @@ class TestsController < Simpler::Controller def index - @time = Time.now + @tests = Test.all + #render plain: "ololo" + status 201 + end + + def show + @test = Test.find(id: @params[:id]) end def create diff --git a/app/views/tests/index.html.erb b/app/views/tests/index.html.erb index 39fce580..673818d6 100644 --- a/app/views/tests/index.html.erb +++ b/app/views/tests/index.html.erb @@ -7,6 +7,11 @@

Simpler framework at work!

-

<%= @time %>

+ - \ No newline at end of file + diff --git a/app/views/tests/show.html.erb b/app/views/tests/show.html.erb new file mode 100644 index 00000000..28ba9135 --- /dev/null +++ b/app/views/tests/show.html.erb @@ -0,0 +1,10 @@ + + + + + Index | Simpler application + + +

<%= @test.title %>

+ + diff --git a/config/routes.rb b/config/routes.rb index 4a751251..904ffb6d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Simpler.application.routes do get '/tests', 'tests#index' - post '/tests', 'tests#create' + get '/tests/:id', 'tests#show' + post '/tests', 'tests#create' end diff --git a/lib/simpler/application.rb b/lib/simpler/application.rb index 711946a9..e5d7d7c5 100644 --- a/lib/simpler/application.rb +++ b/lib/simpler/application.rb @@ -1,6 +1,7 @@ require 'yaml' require 'singleton' require 'sequel' +require 'byebug' require_relative 'router' require_relative 'controller' @@ -28,6 +29,9 @@ def routes(&block) def call(env) route = @router.route_for(env) + route.determ_params(env) + return no_route unless route + controller = route.controller.new(env) action = route.action @@ -36,6 +40,10 @@ def call(env) private + def no_route + [404, { 'Content-Type' => 'text\plain' }, ["Page not found\n"]] + end + def require_app Dir["#{Simpler.root}/app/**/*.rb"].each { |file| require file } end diff --git a/lib/simpler/controller.rb b/lib/simpler/controller.rb index 9383b035..a9d32c25 100644 --- a/lib/simpler/controller.rb +++ b/lib/simpler/controller.rb @@ -3,27 +3,40 @@ module Simpler class Controller - attr_reader :name, :request, :response + attr_reader :name, :request, :response, :params + attr_accessor :headers def initialize(env) @name = extract_name @request = Rack::Request.new(env) @response = Rack::Response.new + @headers = @response.headers + @params = {} end def make_response(action) @request.env['simpler.controller'] = self @request.env['simpler.action'] = action + @request.env['simpler.controller.params'] = @request.env['PATH_INFO'].split('/') + determine_params set_default_headers send(action) - write_response + write_response @response.finish end private + def determine_params + @params[:id] = @request.env['simpler.controller.params'][2] + end + + def status(status) + @response.status = status + end + def extract_name self.class.name.match('(?.+)Controller')[:name].downcase end @@ -33,7 +46,11 @@ def set_default_headers end def write_response - body = render_body + body = if @request.env['simpler.template'].is_a?(Hash) && @request.env['simpler.template'].key?(:plain) + @request.env['simpler.template'][:plain] + else + render_body + end @response.write(body) end diff --git a/lib/simpler/router.rb b/lib/simpler/router.rb index 14b3415c..5c99a22f 100644 --- a/lib/simpler/router.rb +++ b/lib/simpler/router.rb @@ -18,7 +18,6 @@ def post(path, route_point) def route_for(env) method = env['REQUEST_METHOD'].downcase.to_sym path = env['PATH_INFO'] - @routes.find { |route| route.match?(method, path) } end diff --git a/lib/simpler/router/route.rb b/lib/simpler/router/route.rb index 4c66b4b7..9e03cf31 100644 --- a/lib/simpler/router/route.rb +++ b/lib/simpler/router/route.rb @@ -2,19 +2,37 @@ module Simpler class Router class Route - attr_reader :controller, :action + attr_reader :controller, :action, :params def initialize(method, path, controller, action) @method = method @path = path @controller = controller @action = action + @params = {} end def match?(method, path) - @method == method && path.match(@path) + @method == method && correct_path?(path) end + def determ_params(env) + user_path = env['PATH_INFO'] + values = user_path.match(regexp_path) + keys = @path.gsub(':','').match(regexp_path) + + @params = Hash[keys.captures.zip(values.captures)] + end + + private + + def correct_path?(user_path) + user_path.match?(regexp_path) + end + + def regexp_path + Regexp.new (@path.gsub(/(:\w+)/, "(\\w+)") + '\Z') + end end end end From 9e3b4873562fa13c244349c379a3f46eb3102967 Mon Sep 17 00:00:00 2001 From: timbynce Date: Fri, 26 Aug 2022 23:05:46 +0300 Subject: [PATCH 2/5] rubocoped --- .gitignore | 1 + app/controllers/tests_controller.rb | 10 ++++------ app/models/test.rb | 3 ++- config/environment.rb | 2 ++ config/routes.rb | 4 +++- lib/simpler/application.rb | 6 +++--- lib/simpler/controller.rb | 14 +++++++------- lib/simpler/router.rb | 4 ++-- lib/simpler/router/route.rb | 7 ++++--- lib/simpler/view.rb | 4 ++-- 10 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f207b8b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.byebug_history diff --git a/app/controllers/tests_controller.rb b/app/controllers/tests_controller.rb index 422f8cc3..67d529a0 100644 --- a/app/controllers/tests_controller.rb +++ b/app/controllers/tests_controller.rb @@ -1,8 +1,9 @@ -class TestsController < Simpler::Controller +# frozen_string_literal: true +class TestsController < Simpler::Controller def index @tests = Test.all - #render plain: "ololo" + # render plain: "ololo" status 201 end @@ -10,8 +11,5 @@ def show @test = Test.find(id: @params[:id]) end - def create - - end - + def create; end end diff --git a/app/models/test.rb b/app/models/test.rb index 86376668..db135e04 100644 --- a/app/models/test.rb +++ b/app/models/test.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + # Simpler.application.db.create_table(:tests) do # primary_key :id # String :title, null: false # Integer :level, default: 0 # end class Test < Sequel::Model - end diff --git a/config/environment.rb b/config/environment.rb index 7a0d38c3..a566c8d3 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../lib/simpler' Simpler.application.bootstrap! diff --git a/config/routes.rb b/config/routes.rb index 904ffb6d..0efcec16 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + Simpler.application.routes do get '/tests', 'tests#index' get '/tests/:id', 'tests#show' - post '/tests', 'tests#create' + post '/tests', 'tests#create' end diff --git a/lib/simpler/application.rb b/lib/simpler/application.rb index e5d7d7c5..ef16d287 100644 --- a/lib/simpler/application.rb +++ b/lib/simpler/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yaml' require 'singleton' require 'sequel' @@ -7,7 +9,6 @@ module Simpler class Application - include Singleton attr_reader :db @@ -45,7 +46,7 @@ def no_route end def require_app - Dir["#{Simpler.root}/app/**/*.rb"].each { |file| require file } + Dir["#{Simpler.root}/app/**/*.rb"].sort.each { |file| require file } end def require_routes @@ -61,6 +62,5 @@ def setup_database def make_response(controller, action) controller.make_response(action) end - end end diff --git a/lib/simpler/controller.rb b/lib/simpler/controller.rb index a9d32c25..ccbc680d 100644 --- a/lib/simpler/controller.rb +++ b/lib/simpler/controller.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + require_relative 'view' module Simpler class Controller - attr_reader :name, :request, :response, :params attr_accessor :headers @@ -22,7 +23,7 @@ def make_response(action) determine_params set_default_headers send(action) - write_response + write_response @response.finish end @@ -47,10 +48,10 @@ def set_default_headers def write_response body = if @request.env['simpler.template'].is_a?(Hash) && @request.env['simpler.template'].key?(:plain) - @request.env['simpler.template'][:plain] - else - render_body - end + @request.env['simpler.template'][:plain] + else + render_body + end @response.write(body) end @@ -66,6 +67,5 @@ def params def render(template) @request.env['simpler.template'] = template end - end end diff --git a/lib/simpler/router.rb b/lib/simpler/router.rb index 5c99a22f..bef7cf96 100644 --- a/lib/simpler/router.rb +++ b/lib/simpler/router.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + require_relative 'router/route' module Simpler class Router - def initialize @routes = [] end @@ -35,6 +36,5 @@ def add_route(method, path, route_point) def controller_from_string(controller_name) Object.const_get("#{controller_name.capitalize}Controller") end - end end diff --git a/lib/simpler/router/route.rb b/lib/simpler/router/route.rb index 9e03cf31..7bf44109 100644 --- a/lib/simpler/router/route.rb +++ b/lib/simpler/router/route.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true + module Simpler class Router class Route - attr_reader :controller, :action, :params def initialize(method, path, controller, action) @@ -19,7 +20,7 @@ def match?(method, path) def determ_params(env) user_path = env['PATH_INFO'] values = user_path.match(regexp_path) - keys = @path.gsub(':','').match(regexp_path) + keys = @path.gsub(':', '').match(regexp_path) @params = Hash[keys.captures.zip(values.captures)] end @@ -31,7 +32,7 @@ def correct_path?(user_path) end def regexp_path - Regexp.new (@path.gsub(/(:\w+)/, "(\\w+)") + '\Z') + Regexp.new("#{@path.gsub(/(:\w+)/, '(\\w+)')}\\Z") end end end diff --git a/lib/simpler/view.rb b/lib/simpler/view.rb index 19a73b34..7309c725 100644 --- a/lib/simpler/view.rb +++ b/lib/simpler/view.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + require 'erb' module Simpler class View - VIEW_BASE_PATH = 'app/views'.freeze def initialize(env) @@ -34,6 +35,5 @@ def template_path Simpler.root.join(VIEW_BASE_PATH, "#{path}.html.erb") end - end end From 11333ae65de9e78771ed2a1dc3ee53befeb4b8ad Mon Sep 17 00:00:00 2001 From: timbynce Date: Mon, 29 Aug 2022 16:39:16 +0300 Subject: [PATCH 3/5] add logger --- .byebug_history | 199 ++++++++++++++++++-------------- .gitignore | 1 + config.ru | 2 + lib/middleware/historylogger.rb | 31 +++++ lib/simpler/application.rb | 8 +- lib/simpler/controller.rb | 15 +-- lib/simpler/router/route.rb | 2 +- log/app.log | 18 +++ 8 files changed, 174 insertions(+), 102 deletions(-) create mode 100644 lib/middleware/historylogger.rb create mode 100644 log/app.log diff --git a/.byebug_history b/.byebug_history index 9e072068..926b2842 100644 --- a/.byebug_history +++ b/.byebug_history @@ -1,4 +1,117 @@ c +@out_params +c +@out_params +c +v +env['simpler.controller'] +"#{env['simpler.controller'].class}##{env['simpler.action']}" +c +@out_params +c +handler +response +headers +status +c +params +c +@params +c +controller.params +c +controller.params +c +params +c +controller.params +c +controller.params +c +controller.params +c +controller.params +c +controller.params +controller +c +controller.headers +controller.params +c +controller.params +controller.params= +controller.params +c +@params +c +@request.env['simpler.controller.params'] +c +controller.request.env['simpler.controller.params'] +c +controller.request.env['simpler.action'] +controller.request +route.params +controller.route +controller +c +route +c +route.determ_params(env) +env +route +exit +@request.env['simpler.controller'] +@request.env['simpler.contoller.params'] +@request.env['simpler.contoller'] +self +@request.env['simpler.contoller'] +@request.env['simpler.action'] +env['simpler.action'] +{env['simpler.controller'] +#{env['simpler.controller'].class}##{env['simpler.action']}" +exit +@request +exit +env['simpler.action'] +env['simpler.router'] +env['simpler'] +@app.call(env) +env['router'] +env['simpler.router'] +env +exit +env['simpler.controller'] +env +exit +handler +exit +env['simpler.action'] +env['simpler.controller'] +env['simpler.controller'].class +env +env['simpler.controller'].class +#{env{'simpler.action'}} +"#{env['simpler.controller'].class}" +env['simpler.controller'].class +env +@app.call(env) +exit +handler.class +handler +exit +respone +response +header +headers +status +status, header, respone = @app.call(env) +all.status +all +exit +all +env +all +c route_path user_path c @@ -141,89 +254,3 @@ path exit @path path -@params -exit -path.each { |string| @params.push(string) if string.start_with?(':') } -path = @path.split('/') -@params -path.each { |string| @params.push(string) if string.start_with?(':') } -params(path) -path = path.split('/') -path -@path -c -@path -exit -c -@path -c -@path -path -exit -correct_params_count?(path) -@path -path -c -@path -path -exit -@path -path -@path.split('/').size -path.split('/').size -correct_params_count?(path) -exit -@method -@path -path -exit -method -@routes -exit -@routes -@path -@routes -@route -exit -@routes -env -env['PATH_INFO'] -@request -@path -exit -route.map { |param| param?(param) ? '[[:alnum:]]' :param } -route = params(@path) -params(@path) -@path -exit -@routes -exit -env['PATH_INFO'] -env['PATH_INFO']) -env -exit -@path -exctract_params(@path) -exit -correct_path -correct_path?(path) -path -exit -path -method -@routes[2] -@routes[0] -@routes[1] -@routes.find { |route| route.match?(method, path) -@routes -route -exit -@method -method -path -exit -@path -exit -@params -@request.env['PATH_INFO'].split('/')[2] -@request.env['PATH_INFO'] diff --git a/.gitignore b/.gitignore index f207b8b9..19353b96 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.byebug_history +/app/app.log diff --git a/config.ru b/config.ru index 3060cc20..1437c576 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ require_relative 'config/environment' +require_relative 'lib/middleware/historylogger' +use HistoryLogger run Simpler.application diff --git a/lib/middleware/historylogger.rb b/lib/middleware/historylogger.rb new file mode 100644 index 00000000..a87a454d --- /dev/null +++ b/lib/middleware/historylogger.rb @@ -0,0 +1,31 @@ +class HistoryLogger + attr_reader :out_params + + def initialize(app) + @app = app + @out_params = {} + #@logger = Logger.new(Simpler.root.join('log/app.log')) + end + + def call(env) + status, headers, response = @app.call(env) + + @out_params[:Request] = "#{env['REQUEST_METHOD']} #{env['REQUEST_PATH']}" + @out_params[:Handler] = "#{env['simpler.controller'].class}##{env['simpler.action']}" + @out_params[:Parameters] = "#{env['simpler.controller.params']}" + @out_params[:Response] = "#{status} [#{headers['Content-Type']}] #{env['simpler.template_path']}" + + add_log(@out_params) + + [status, headers, response] + end + + def add_log(content) + logfile = "log/app.log" + File.open(logfile, 'a') do |file| + content.each{ |k, v| file << ("#{k}: #{v}\n") } + file << "\n" + end + end + +end diff --git a/lib/simpler/application.rb b/lib/simpler/application.rb index ef16d287..85e4270b 100644 --- a/lib/simpler/application.rb +++ b/lib/simpler/application.rb @@ -30,10 +30,12 @@ def routes(&block) def call(env) route = @router.route_for(env) - route.determ_params(env) - return no_route unless route - controller = route.controller.new(env) + return no_route unless route + + route.determ_params(env) + controller = route.controller.new(env) + controller.params = route.params action = route.action make_response(controller, action) diff --git a/lib/simpler/controller.rb b/lib/simpler/controller.rb index ccbc680d..a30c5e30 100644 --- a/lib/simpler/controller.rb +++ b/lib/simpler/controller.rb @@ -4,8 +4,8 @@ module Simpler class Controller - attr_reader :name, :request, :response, :params - attr_accessor :headers + attr_reader :name, :request, :response + attr_accessor :headers, :params def initialize(env) @name = extract_name @@ -18,9 +18,8 @@ def initialize(env) def make_response(action) @request.env['simpler.controller'] = self @request.env['simpler.action'] = action - @request.env['simpler.controller.params'] = @request.env['PATH_INFO'].split('/') + @request.env['simpler.controller.params'] = @incoming_params - determine_params set_default_headers send(action) write_response @@ -30,10 +29,6 @@ def make_response(action) private - def determine_params - @params[:id] = @request.env['simpler.controller.params'][2] - end - def status(status) @response.status = status end @@ -60,10 +55,6 @@ def render_body View.new(@request.env).render(binding) end - def params - @request.params - end - def render(template) @request.env['simpler.template'] = template end diff --git a/lib/simpler/router/route.rb b/lib/simpler/router/route.rb index 7bf44109..d553159d 100644 --- a/lib/simpler/router/route.rb +++ b/lib/simpler/router/route.rb @@ -22,7 +22,7 @@ def determ_params(env) values = user_path.match(regexp_path) keys = @path.gsub(':', '').match(regexp_path) - @params = Hash[keys.captures.zip(values.captures)] + @params = Hash[keys.captures.map(&:to_sym).zip(values.captures)] end private diff --git a/log/app.log b/log/app.log new file mode 100644 index 00000000..cc0f7643 --- /dev/null +++ b/log/app.log @@ -0,0 +1,18 @@ +Request: GET /tests/1 +Handler: TestsController#show +Parameters: +Response: 200 [text/html] +Request: GET /tests/1 +Handler: TestsController#show +Parameters: +Response: 200 [text/html] +Request: GET /tests/1 +Handler: TestsController#show +Parameters: +Response: 200 [text/html] + +Request: GET /tests +Handler: TestsController#index +Parameters: +Response: 201 [text/html] + From f9ece49ba4bc0e9a716c6796f8a1cddc8709ca9e Mon Sep 17 00:00:00 2001 From: timbynce Date: Mon, 29 Aug 2022 16:39:41 +0300 Subject: [PATCH 4/5] fix logger --- lib/middleware/historylogger.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/middleware/historylogger.rb b/lib/middleware/historylogger.rb index a87a454d..e56da20f 100644 --- a/lib/middleware/historylogger.rb +++ b/lib/middleware/historylogger.rb @@ -4,7 +4,6 @@ class HistoryLogger def initialize(app) @app = app @out_params = {} - #@logger = Logger.new(Simpler.root.join('log/app.log')) end def call(env) From 5f3c109c7b9d7c00c5e9106c0d1b10c209c588fb Mon Sep 17 00:00:00 2001 From: timbynce Date: Mon, 29 Aug 2022 16:47:34 +0300 Subject: [PATCH 5/5] rubocoped --- lib/middleware/historylogger.rb | 9 +++++---- lib/simpler/application.rb | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/middleware/historylogger.rb b/lib/middleware/historylogger.rb index e56da20f..bd131273 100644 --- a/lib/middleware/historylogger.rb +++ b/lib/middleware/historylogger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class HistoryLogger attr_reader :out_params @@ -11,7 +13,7 @@ def call(env) @out_params[:Request] = "#{env['REQUEST_METHOD']} #{env['REQUEST_PATH']}" @out_params[:Handler] = "#{env['simpler.controller'].class}##{env['simpler.action']}" - @out_params[:Parameters] = "#{env['simpler.controller.params']}" + @out_params[:Parameters] = (env['simpler.controller.params']).to_s @out_params[:Response] = "#{status} [#{headers['Content-Type']}] #{env['simpler.template_path']}" add_log(@out_params) @@ -20,11 +22,10 @@ def call(env) end def add_log(content) - logfile = "log/app.log" + logfile = 'log/app.log' File.open(logfile, 'a') do |file| - content.each{ |k, v| file << ("#{k}: #{v}\n") } + content.each { |k, v| file << ("#{k}: #{v}\n") } file << "\n" end end - end diff --git a/lib/simpler/application.rb b/lib/simpler/application.rb index 85e4270b..88f094ed 100644 --- a/lib/simpler/application.rb +++ b/lib/simpler/application.rb @@ -32,9 +32,9 @@ def call(env) route = @router.route_for(env) return no_route unless route - + route.determ_params(env) - controller = route.controller.new(env) + controller = route.controller.new(env) controller.params = route.params action = route.action