aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-07-15 18:07:41 -0400
committerPaul Duncan <pabs@pablotron.org>2016-07-15 18:07:41 -0400
commit63bc54d966831929eb66da8e06291fd924fb4aef (patch)
tree26b8db0429f7a21408bddf5a5efb72ba1526ad5d /src
parent959e2baf6fc78c0fba694af27531b8c9d6ed5f7f (diff)
downloadguff-63bc54d966831929eb66da8e06291fd924fb4aef.tar.bz2
guff-63bc54d966831929eb66da8e06291fd924fb4aef.zip
use YAML.mapping for init data
Diffstat (limited to 'src')
-rw-r--r--src/guff.cr27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/guff.cr b/src/guff.cr
index 1e536cf..8ea29fa 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -2711,14 +2711,23 @@ module Guff
end
class InitAction < Action
+ class Data
+ YAML.mapping({
+ init_sql: Array(String),
+ add_user: String,
+ test_posts: Array(String),
+ })
+
+ def self.load(system_dir : String) : Data
+ self.from_yaml(File.read(File.join(system_dir, "init.yaml")))
+ end
+ end
+
def initialize(config : Config)
super(config)
# read init data
- @data = YAML.parse(File.read(File.join(
- @config.system_dir,
- "init.yaml"
- )))
+ @data = Data.load(@config.system_dir)
end
def run
@@ -2726,8 +2735,8 @@ module Guff
Dir.mkdir(@config.data_dir) unless Dir.exists?(@config.data_dir)
Guff::Database.new(@config.db_path) do |db|
- @data["sql"]["init"].each do |sql|
- db.query(sql.as_s)
+ @data.init_sql.each do |sql|
+ db.query(sql)
end
# gen random password and add admin user
@@ -2747,7 +2756,7 @@ module Guff
email : String,
password : String
) : Int64
- db.query(@data["sql"]["add_user"].as_s, [
+ db.query(@data.add_user, [
name,
email,
Password.create(password),
@@ -2758,8 +2767,8 @@ module Guff
private def add_test_posts(db)
# STDERR.puts "DEBUG: adding test data"
- @data["sql"]["test_posts"].each do |sql|
- db.query(sql.as_s)
+ @data.test_posts.each do |sql|
+ db.query(sql)
end
end
end