Replaced the rerun gem with guard-rack; added some work to support Windows better; added a way to configure the application with config.yaml

This commit is contained in:
Gregory Ballantine 2023-03-09 15:48:33 -05:00
parent 39ebf6a535
commit 46e4e5c079
8 changed files with 49 additions and 11 deletions

3
.gitignore vendored
View File

@ -59,6 +59,9 @@ build-iPhoneSimulator/
# Local database storage
data/stgm.db
# Local configuration
data/config.yaml
# Node modules for Grunt.js
node_modules/

View File

@ -12,6 +12,6 @@ gem 'kramdown', '~> 2.4'
gem 'pandoc-ruby', '~> 2.1'
# Use rerun gem to auto-reload app
gem 'rerun'
gem 'guard-rack'
gem 'wdm', '>= 0.1.0' if Gem.win_platform?

View File

@ -1,18 +1,42 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.3)
ffi (1.15.5)
ffi (1.15.5-x64-mingw-ucrt)
formatador (1.1.0)
guard (2.18.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-rack (2.2.1)
ffi
guard (~> 2.3)
spoon
kramdown (2.4.0)
rexml
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
lumberjack (1.2.8)
method_source (1.0.0)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
nenv (0.3.0)
nio4r (2.5.8)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
pandoc-ruby (2.1.7)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
puma (6.1.1)
nio4r (~> 2.0)
rack (2.2.6.2)
@ -21,11 +45,10 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rerun (0.14.0)
listen (~> 3.0)
rexml (3.2.5)
ruby2_keywords (0.0.5)
sequel (5.66.0)
shellany (0.0.1)
sinatra (3.0.5)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
@ -37,8 +60,11 @@ GEM
rack-protection (= 3.0.5)
sinatra (= 3.0.5)
tilt (~> 2.0)
spoon (0.0.6)
ffi
sqlite3 (1.6.1-x64-mingw-ucrt)
sqlite3 (1.6.1-x86_64-linux)
thor (1.2.1)
tilt (2.1.0)
wdm (0.1.1)
@ -47,10 +73,10 @@ PLATFORMS
x86_64-linux
DEPENDENCIES
guard-rack
kramdown (~> 2.4)
pandoc-ruby (~> 2.1)
puma (~> 6.1)
rerun
sequel (~> 5.66)
sinatra (~> 3.0)
sinatra-contrib (~> 3.0)

5
Guardfile Normal file
View File

@ -0,0 +1,5 @@
guard 'rack' do
watch('Gemfile.lock')
watch('server.rb')
watch(%r{^(lib)/.*})
end

View File

@ -16,10 +16,6 @@ end
namespace :server do
task :dev do
%x{ruby server.rb}
end
task :reload do
%x{rerun --ignore 'assets/*' --ignore 'public/*' --no-notify 'ruby server.rb'}
%x{guard}
end
end

2
config.ru Normal file
View File

@ -0,0 +1,2 @@
require_relative './server'
run Sinatra::Application

View File

@ -2,8 +2,14 @@ require 'yaml'
class Config
DEFAULT_CONFIG = 'data/defaults.yaml'
def initialize(config_path)
@data = YAML::load_file(config_path)
@data = YAML::load_file(DEFAULT_CONFIG)
if File.exists?(config_path)
@data.merge!(YAML::load_file(config_path))
end
end
def get(key, depth = 0)

View File

@ -11,7 +11,7 @@ set :public_folder, __dir__ + '/public'
set :views, settings.root + '/views'
# Load configuration file
$conf = Config.new(File.join(__dir__, 'data/defaults.yaml'))
$conf = Config.new(File.join(__dir__, 'data/config.yaml'))
# Initialize logging
logger = Logger.new(STDOUT)