From 38cc4945d5a8150bf86721d445512daff7b2820a Mon Sep 17 00:00:00 2001 From: ippachi Date: Tue, 11 Feb 2020 00:02:20 +0900 Subject: [PATCH] Add hanami support --- lib/config.rb | 4 ++++ lib/config/integrations/hanami.rb | 9 +++++++++ .../config/hanami_install_generator.rb | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 lib/config/integrations/hanami.rb create mode 100644 lib/generators/config/hanami_install_generator.rb diff --git a/lib/config.rb b/lib/config.rb index 471b113d..c9dcc5ba 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -80,3 +80,7 @@ def self.reload! # Sinatra integration require('config/integrations/sinatra') if defined?(::Sinatra) + +# Hanami integration and generator +require('generators/config/hanami_install_generator') if defined?(::Hanami) +require('config/integrations/hanami') if defined?(::Hanami) diff --git a/lib/config/integrations/hanami.rb b/lib/config/integrations/hanami.rb new file mode 100644 index 00000000..0cb44fb1 --- /dev/null +++ b/lib/config/integrations/hanami.rb @@ -0,0 +1,9 @@ +require "config/rack/reloader" + +::Hanami.plugin do + env = ::Hanami.env + root = ::Hanami.root + Config.load_and_set_settings(Config.setting_files(File.join(root, 'config'), env)) + + middleware.use(::Config::Rack::Reloader) if env == "development" +end diff --git a/lib/generators/config/hanami_install_generator.rb b/lib/generators/config/hanami_install_generator.rb new file mode 100644 index 00000000..c5032749 --- /dev/null +++ b/lib/generators/config/hanami_install_generator.rb @@ -0,0 +1,18 @@ +module Config + module Generators + class HanamiInstallGenerator < ::Hanami::CLI::Commands::Command + requires "environment" + + desc "Generates a custom Hanami Config initializer file." + + def call(*) + files.cp File.expand_path("../templates/config.rb", __FILE__), ::Hanami.root.join("config/initializers/config.rb") + files.cp File.expand_path("../templates/settings.yml", __FILE__), ::Hanami.root.join("config/settings.yml") + files.cp File.expand_path("../templates/settings.local.yml", __FILE__), ::Hanami.root.join("config/settings.local.yml") + FileUtils.cp_r File.expand_path("../templates/settings", __FILE__), ::Hanami.root.join("config/settings") + end + end + end +end + +::Hanami::CLI.register "generate config", Config::Generators::HanamiInstallGenerator