diff options
-rw-r--r-- | src/guff.cr | 29 | ||||
-rw-r--r-- | src/guff/context.cr | 28 |
2 files changed, 28 insertions, 29 deletions
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 |