Instead of File.basename(file_path), you can just use "name".

I wonder, if there was a canonical function that worked regardless of versioned_cookbooks, on CookbookDir, maybe you wouldn't even need the "if" here.  Just say loader.instance_variable_set(:@cookbook_name, CookbookDir.canonical_cookbook_name(name))