Class: Ezframe::Controller
Class Method Summary collapse
- .exec(request, response) ⇒ Object
- .file_not_found(response) ⇒ Object
- .init ⇒ Object
- .login? ⇒ Boolean
- .user ⇒ Object
- .warden ⇒ Object
Class Method Details
.exec(request, response) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ezframe/controller.rb', line 13 def exec(request, response) @request = request page_instance, method, url_params, class_opts = Route::choose(request) EzLog.debug("Controller.exec: path=#{request.path_info}, params=#{request.params}, class=#{page_instance.class}, method=#{method}, url_params=#{url_params}, class_opts=#{class_opts}") if !page_instance || page_instance == 404 file_not_found(response) return end @request.env["url_params"] = url_params opt_auth = class_opts[:auth] @session = @request.env['rack.session'] if !@session[:user] && Config[:auth] && (!opt_auth || opt_auth != "disable") EzLog.debug("authenticate!") warden.authenticate! EzLog.info "Controller.exec: warden.options = #{@request.env['warden.options']}" end # session["in_controller"] = "set in controller" EzLog.debug "rack.session.keys=#{@session.keys}" if @session page_instance.set_request(@request) body = page_instance.send(method) # 戻り値によるレスポンス生成 if body.is_a?(Hash) || body.is_a?(Array) # EzLog.debug("Controller: body = #{body}") json = JSON.generate(body) response.body = [ json ] response['Content-Type'] = 'application/json; charset=utf-8' else response.body = [ body ] response['Content-Type'] = 'text/html; charset=utf-8' end response.status = 200 # EzLog.debug("Controller.exec: response.body=#{response.body}") end |
.file_not_found(response) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ezframe/controller.rb', line 49 def file_not_found(response) response.status = 404 response['Content-Type'] = 'text/html; charset=utf-8' template_file = ("#{Config[:template_dir]}/404.html") # puts template_file if File.exist?(template_file) body = File.read(template_file) else body = Html.convert(Ht.p("file not found")) end response.body = [ body ] end |
.init ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/ezframe/controller.rb', line 5 def init Config.init ColumnSets.init DB.init Message.init Auth.init if Config[:auth] end |
.login? ⇒ Boolean
66 67 68 |
# File 'lib/ezframe/controller.rb', line 66 def login? !!warden.user end |
.user ⇒ Object
70 71 72 |
# File 'lib/ezframe/controller.rb', line 70 def user warden.user end |
.warden ⇒ Object
62 63 64 |
# File 'lib/ezframe/controller.rb', line 62 def warden @request.env["warden"] end |