schovi / baked_file_system

Virtual File System for Crystal language. Embedding your assets into final binary.
MIT License
177 stars 18 forks source link

Refactor creation of a baked file system #25

Closed straight-shoota closed 6 years ago

straight-shoota commented 6 years ago

Prior to this PR you would create a custom type and call BakedFileSystem.load(path) from that types scope. This would extend BakedFileSystem and add baked files (created from local folder path) to the file system.

With this PR, you need to exlicitly extend the custom type from BakedFileSystem. This extension adds macros and class methods for baking a folder or a specific file to the type scope:

# previously:
class MyFileSystem
  BakedFileSystem.load("path/to/folder")
end
# now:
class MyFileSystem
  extend BakedFileSystem
  bake_folder "path/to/folder"
end

This is a breaking change, but IMHO it's very much worth it. It allows adding files from multiple folders and as well custom BakedFile instances using bake_file. While being a bit more characters, it makes it explicit that MyFileSystem extends BakedFileSystem - which was previously hidden by BakedFileSystem.load. This makes things more transparent.