Skip to content

Commit

Permalink
Using a regex will generalize this a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
davebenvenuti committed Jan 22, 2025
1 parent 7dab057 commit e39361d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/protoboeuf/autoloadergen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ def initialize(module_filename, parent_module = "ProtoBoeuf::Google")
# Build a map of what we want to autoload :ConstantName => protoboeuf/require/path
@require_paths_for_child_constants = child_ruby_filenames.each_with_object({}) do |filename, require_paths|
child_constants = constants_for_child_ruby_filename(filename)
# For the autoloader_full_module_name we can just pick the first child constant we come across and take the
# first three parts. For example, ProtoBoeuf::Google::Api::FieldBehavior would be ProtoBoeuf::Google::Api.
if @autoloader_module_name.nil?
autoloader_full_module_name = child_constants.first.split("::")[0..2].join("::")
# For the autoloader_full_module_name we can just pick the first child constant we come across and take up until
# the first child constant of the parent_module.
# For example, ProtoBoeuf::Google::Api::FieldBehavior would be ProtoBoeuf::Google::Api.
if autoloader_full_module_name.nil?
autoloader_full_module_name = child_constants.first.sub(/(#{parent_module}::.+?)::.*/, "\\1")
end

# Make our absolute filename relative to the base lib directory for our autoload calls.
Expand Down

0 comments on commit e39361d

Please sign in to comment.