Skip to content

Commit

Permalink
Auto/eager load constants for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
davebenvenuti committed Jan 15, 2025
1 parent b520393 commit cafa5bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/protoboeuf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

module Protoboeuf
module ProtoBoeuf
autoload :CodeGen, "protoboeuf/codegen"
autoload :Google, "protoboeuf/google"
end
5 changes: 5 additions & 0 deletions lib/protoboeuf/google.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

# There isn't a clean 1:1 mapping between constants and *.rb files, so eager load instead of autoload.

Dir[File.expand_path("**/*.rb", __dir__)].each { |file| require file }
5 changes: 3 additions & 2 deletions test/gem_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def test_can_be_required
::ProtoBoeuf
require "protoboeuf/codegen"
# The following should auto/eagerload
::ProtoBoeuf::CodeGen
::ProtoBoeuf::Google::Api::FieldBehavior
::ProtoBoeuf::Google::Protobuf::Any
exit 0
RUBY
Expand Down

0 comments on commit cafa5bd

Please sign in to comment.