- Who has used a gem?
- Such as Rails, Sinatra, Bundler, Rake
- Who has written a gem?
- Share code between projects
- Reduce duplication
- Open the source, receive contributions
- The joy of sharing
- Patrick Byrne
- website and twitter handle
- Formerly of Sport Ngin, currently of Dribbble
- We'll be skipping the boring, mechanical parts of writing gems
- Google is good for that
bundle gem GEMNAME
is a great place to start
- I want to talk about some of the less obvious benefits of building a gem
- I'll be using okcomputer as a concrete example
- It's a gem that adds configurable health check endpoints to your Rails app
- Tremendously useful tool
- Provides a lightweight health check URL for your load balancer to stop sending traffic to app servers experincing trouble
- But you can do a lot more than that
- With okcomputer, you can:
- Add a check to ensure that your Delayed Job or Resque queues haven't gotten backed up
- Add a check that you can connect to an external service that you depend on
- Then hook these up to Pingdom or another tool to monitor, track, and alert on failures
- Had used fitter_happier in our primary app
- Created a second app, and wanted to check our MongoDB connection on it and
Resqueue queues
- No way to customize, so we monkey-patch
- Third app needs these monkey patches, too. And a fourth
- Stop the madness. We can do better than this
- The idea of okcomputer is born
- I said I'd focus on the less obvious benefits, but this obvious benefit is too important to ignore
- Write the gem once. Put it in all your apps
- Create all the different kinds of checks that we want (ActiveRecord, Mongoid, Delayed Job, Resque, etc.), then turn them on in the apps that need them
- If you find yourself copying and pasting support classes from project to project, you owe it to yourself and your team to extract that out into a gem
- Another show of hands. How many of you work on a "legacy" application?
- The weight of past decisions factor into new development
- Libraries used
- Testing style
- Code conventions
- Can be a bit boring, to feel constrained in this way
- Everyone loves to start something fresh and new
- It can get the blood pumping
- A new gem gives you an excellent opportunity to start with a fresh sheet of paper, unbound by the rest of your app(s)
- Even if you work in a single application, so you aren't saving any duplication, moving some code that isn't business logic can provide value
- If you're building something that can be released to the public, you're
probably more likely to:
- Write a good README
- Provide sensible defaults
- Make it reasonably complete
- Try to impress anyone who will see it
- If it was in your main app, you might be tempated to throw it together and
move on
- As a separate project, you're free to really polish it and iterate independent of your app
- You're free to try new tools and new techniques
- It's far easier to try these out in a stand-alone project than to change course in your existing app
- Use Test:Unit at work, but have always wanted to try RSpec or Minitest? Do it!
- Can't bring your team on board with TDD? Prove it with how well it works for your gem.
- Want to try documentation with TomDoc or YARD? Now's a great chance!
- Think you have a better coding convention than what's in your main app(s)? Try it here.
- Want to really put Sandi Metz's 4 rules to the test? No better time than now.
- Want to try these neat SOLID principles you keep reading about in blog posts?
- Code Climate? Free for open source
- Travis CI? Also free for open source
- Coveralls? Also free for open source
- This is the most important part of the experiment.
- Are things better with this or that change? Why? Why not?
- If they are better, you have ammunition to improve your existing app with your findings
- Closely related to the above point
- Depending on your organization, you might only be experiencing a small
portion of the project's lifecycle
- Here you get to own everything
- Never built a Rails Engine before?
- Never written a test before?
- Never started a project from scratch?
- TBD