There is a github repo I want to fetch code from which isn't a gem. It is a bunch of javascript files, and it has no gem version. Can I add this to the Gemfile and define where it should be stored (under the lib/assets) directory, or will I have to manage this with a git submodule?
2 Answers
I vote for: Keep the Gemfile clean, go for the submodules.
-
Thanks. Is there a way to only include certain directories or files from the submodule before I add it? Like say I wanted to exclude the directory 'demo' and all files, just include 'src'?– user419017Commented Sep 17, 2012 at 6:51
-
-
Thats not a question of style. Bundler can only manage Gems. On the other hand, submodules are often a bad advice as they are not that easy to use in the long run and promote tight coupling instead of fostering separation of concerns. Commented Sep 17, 2012 at 8:09
Bundler manages gems, not arbitrary repositories. That said, if you just want to use some assets, you can easily package them as a gem to allow them to hock into the assets pipeline. This brings you the upside of allowing you to use all the tools for managing gems as well as proper separation of concerns.
You need to add a rails engine for that. For that simply put your assets into the vendor/assets
directory of the new gem in a directory structure similar to the main assets
directory of your main app. Additionally you need to add a new ruby class into lib/your_gem.rb
with this content:
module MyGem
class Engine < Rails::Engine
end
end
This registers the gem as a rails engine and provides the assets to the assets pipeline.
Finally add a gemspec and you are finished. A basic gem structure can be Also be created by the bundle gem
command.