Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hanami support #272

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,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)
9 changes: 9 additions & 0 deletions lib/config/integrations/hanami.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions lib/generators/config/hanami_install_generator.rb
Original file line number Diff line number Diff line change
@@ -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