Create a Ruby Gem. Real World, play by play. Part 4
Part 4 of the Gem creation tutorial that follows the conception of a real Gem.
In the last episode, Part 3, I finished wiring up the oauth_client and create_service_for methods. In this final installment, I will complete and publish the Gem, quickbooks-ruby-base.
- Up until this point I haven't run all the specs just individual ones. Before I move on I run the entire test suite with a
bundle exec rakecommand. - In another tmux window I switch to a sample QuickBooks/Rails app, minimulcasts.
- I add
quickbooks-ruby-baseto the Gemfile, pointing it to the local path. - I run
bundle install. - I edit
config/initializers/quickbooks.rbto add the Gem's persistent configuration settings. - After saving
config/initializers/quickbooks.rbI enter therails console - This was because I forgot to expose 'service'. I go back to the Gem code (
lib/quickbooks/base.rb) and add it. - Within the existing rails console I have to reload the Gem changes I made to
base.rb. To do that without stopping and restarting the rails console I do the following: - I get another error but at least the 'service' method is working.
- Upon further investigation, the Intuit App. API key and secret are not getting set.
- The problem is not within the
Quickbooks::Baseconfiguration code but the bash shell env values are not available in the tmux window that I am runningrails console. - With that is it time to work on the
README. - The
bundle gemcommand gives me a boilerplate README to get going. - To aid me in writing a great README I leverage the fantastic Ruby Gem, github-markdown-preview
- After completing the README I am ready to push to Github.
- The final step is to publish to Rubygems.org
- I sign in.
- I search over at Rubygems to verify.
$ cd ~/www/labs/minimulcasts
$ bundle install
oauth_consumer as the Gem's default is $qb_oauth_consumer for that setting.
undefined method 'service' running through some sample commands.
:!echo %:p command to get the full path of the file I changed.
base.rb.
IntuitRequestException.Hey Minimul, you forgot to add a test for the attr_reader :service code you added!
No, I already tested it in the console. The attr_reader is Ruby core code and I don't need to test it formally. The console test gives me enough confidence to move on. See Part 3 for more on my test philosophy.
source ~/.profile, which will inject my environmental variables from ~/.profile into my current bash shell. Restart the rails console and all is well.Hey Minimul, where is the inline documentation for RDoc or YARD support?
I normally don't find RDoc-like docs useful and consequently don't read them much. Perhaps, if this Gem becomes widely used would I go back and add inline documentation/comments but for now I don't want yet another "weight" preventing me from releasing the Gem. A good README is essential so I am going to focus my efforts there.
github-markdown-preview README.md and then copy the file:// location returned.
Do I have to restart github-markdown-preview each time I make a change?
No, just refresh the file:// url and the README modifications will display.
bundle gem command in Part 1.
git status I git add(aliased as ga in the figure) files that need to constitute the Gem.
git remote and git push commands.
That concludes the "Create a Ruby Gem. Real World, play by play." series.
Wow, that four-part tutorial clocked in at a little over 1.5 hours of video content (~95 minutes). I sincerely hope it aids and encourages you to contribute and distribute your knowledge through creating a Ruby Gem. Here are the other installments:
- Pushed on 05/08/2014 by Christian
