Skip to content

Commit

Permalink
Set up Zeitwerk for code loading (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley authored May 24, 2024
1 parent 96052fc commit 371b9d2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
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

0 comments on commit 371b9d2

Please sign in to comment.