Reputation: 7373
This may seem quite a broad question, but I've searched around and didn't find ways to avoid duplication between different apps. Only inside an app.
I'm working with three different rails applications for some time now. From time to time I find myself refactoring some file like my icons_helper.rb
. When I finish. Its better than before but different from the same file in my other two rails apps.
Other typical examples of duplicated code:
What should I do to avoid this inter-app duplication? Is writing a gem that wraps those files the best choice?
Upvotes: 1
Views: 66
Reputation: 11689
That's simple, make your own gem. You can keep it closed (use git: 'git location'
) or make it open and use rubygems.
You can start with bundle gem yourgem
, and this is a very good article on how to build your first gem
You manage this as a completely separate project. We are doing this in our company and it's working great
As suggested, you want to have tests in your gem, for sure. It won't slow down debugging: errors raised by the gem are displayed as gemname/file_in_gem:line_number
so you'll still detect problems easily. Also, if you are following good testing practices, you shouldn't test your gem in the other applications: the gem is already tested in its own codebase.
You might want to check this article about splitting a rails application into a lot of sub-engines. Obviously this is an extreme approach which will provide good results only in very large projects and bigger teams, but it shows you that it's actually a good idea splitting a Rails application.
Upvotes: 2
Reputation: 106792
If you want to reuse code in multiple applications then I suggest to extract that code into a Gem and require that Gem in each application.
Upvotes: 1