aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-07-15 20:11:38 -0400
committerPaul Duncan <pabs@pablotron.org>2016-07-15 20:11:38 -0400
commit817340c34f8287bc13424c0871240d1f52f20494 (patch)
tree76672ae278de5ffda318c5b308d643cfbf6f3eb1
parentebcd06d010367654e88d777cf4721be05d6e690e (diff)
downloadguff-817340c34f8287bc13424c0871240d1f52f20494.tar.bz2
guff-817340c34f8287bc13424c0871240d1f52f20494.zip
refactor context
-rw-r--r--src/guff.cr29
-rw-r--r--src/guff/context.cr28
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