From 46e4e5c0797f1c668dea23ee56911d4b405a2b04 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Thu, 9 Mar 2023 15:48:33 -0500 Subject: [PATCH] Replaced the rerun gem with guard-rack; added some work to support Windows better; added a way to configure the application with config.yaml --- .gitignore | 3 +++ Gemfile | 2 +- Gemfile.lock | 32 +++++++++++++++++++++++++++++--- Guardfile | 5 +++++ Rakefile | 6 +----- config.ru | 2 ++ lib/config.rb | 8 +++++++- server.rb | 2 +- 8 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 Guardfile create mode 100644 config.ru diff --git a/.gitignore b/.gitignore index a5fcad4..b5de16f 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,9 @@ build-iPhoneSimulator/ # Local database storage data/stgm.db +# Local configuration +data/config.yaml + # Node modules for Grunt.js node_modules/ diff --git a/Gemfile b/Gemfile index c5e1820..e370834 100644 --- a/Gemfile +++ b/Gemfile @@ -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? diff --git a/Gemfile.lock b/Gemfile.lock index b00eac6..6da35e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..d1111a6 --- /dev/null +++ b/Guardfile @@ -0,0 +1,5 @@ +guard 'rack' do + watch('Gemfile.lock') + watch('server.rb') + watch(%r{^(lib)/.*}) +end \ No newline at end of file diff --git a/Rakefile b/Rakefile index e38a8b4..26efb05 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..21e2b15 --- /dev/null +++ b/config.ru @@ -0,0 +1,2 @@ +require_relative './server' +run Sinatra::Application diff --git a/lib/config.rb b/lib/config.rb index fe21f39..29be78e 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -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) diff --git a/server.rb b/server.rb index 495234f..43d0743 100644 --- a/server.rb +++ b/server.rb @@ -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)