From 817340c34f8287bc13424c0871240d1f52f20494 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 15 Jul 2016 20:11:38 -0400 Subject: refactor context --- src/guff.cr | 29 ----------------------------- src/guff/context.cr | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 29 deletions(-) create mode 100644 src/guff/context.cr (limited to 'src') diff --git a/src/guff.cr b/src/guff.cr index c1acd8b..3fecd10 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -1325,35 +1325,6 @@ module Guff end end - class Context - getter :config, :dbs - - def initialize(@config : Config) - @dbs = DatabasePair.new(@config.db_path, development?) - end - - def models - @models ||= ModelSet.new(self) - end - - def session - @session ||= Session.new(self) - end - - def user_id : Int64? - session["user_id"]? ? session["user_id"].to_i64 : nil - end - - def has_role?(roles : Array(String)) - id = user_id - id ? models.user.has_role?(id, roles) : false - end - - def development? - @is_development ||= (@config.env == "development") as Bool - end - end - module APIs module PostAPI def do_post_get_posts(params : HTTP::Params) diff --git a/src/guff/context.cr b/src/guff/context.cr new file mode 100644 index 0000000..7ab7b1e --- /dev/null +++ b/src/guff/context.cr @@ -0,0 +1,28 @@ +class Guff::Context + getter :config, :dbs + + def initialize(@config : Config) + @dbs = DatabasePair.new(@config.db_path, development?) + end + + def models + @models ||= ModelSet.new(self) + end + + def session + @session ||= Session.new(self) + end + + def user_id : Int64? + session["user_id"]? ? session["user_id"].to_i64 : nil + end + + def has_role?(roles : Array(String)) + id = user_id + id ? models.user.has_role?(id, roles) : false + end + + def development? + @is_development ||= (@config.env == "development") as Bool + end +end -- cgit v1.2.3