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

Set up Zeitwerk for code loading #1

Merged
merged 1 commit into from
May 24, 2024
Merged
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: 3 additions & 1 deletion hanami-db.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require_relative "lib/hanami/db/version"

Gem::Specification.new do |spec|
spec.name = "hanami-db"
spec.version = "0.0.0"
spec.version = Hanami::DB::VERSION
spec.authors = ["Hanami team"]
spec.email = ["[email protected]"]
spec.summary = "The database layer for Hanami apps"
Expand Down
20 changes: 20 additions & 0 deletions lib/hanami/db.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# frozen_string_literal: true

require "zeitwerk"

module Hanami
module DB
require_relative "db/gem_inflector"

# @api private
# @since 2.2.0
def self.loader
@loader ||= Zeitwerk::Loader.new.tap do |loader|
root = File.expand_path("..", __dir__)

loader.inflector = GemInflector.new("#{root}/hanami/db.rb")
loader.tag = "hanami-db"
loader.push_dir root
loader.ignore(
"#{root}/hanami-db.rb",
"#{root}/hanami/db/gem_inflector.rb"
)
end
end
loader.setup
end
end
14 changes: 14 additions & 0 deletions lib/hanami/db/gem_inflector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Hanami
module DB
# @api private
class GemInflector < Zeitwerk::GemInflector
def camelize(basename, _abspath)
return "DB" if basename == "db"

super
end
end
end
end
7 changes: 7 additions & 0 deletions lib/hanami/db/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Hanami
module DB
VERSION = "0.0.0"
end
end
Loading