Create a Ruby Gem. Real World, play by play. Part 2
Part 2 of the Gem creation tutorial that follows the conception of a real Gem.
In Part 1 I went over some of the basics in why you would want to create a Gem, naming the Gem, namespace considerations, directory structure, .gemspec file details, and setting up a basic Rspec test. In part 2, I start to dig into the challenges proposed by the code that I would like to formulate into a Gem.
In addition, I started with some code that I am already using on a project. The name of the file is qb_base.rb
. I am going to be cutting and pasting that code over to my new Gem. The first stumbling blocks I run into is that the code is hard-wired to its environment. I need to find a way to overcome these obstacles and make the Gem generic "enough" to easily include into another application's surroundings.
- First, I open the code that I want to translate into a new Gem.
- Before I get to ahead of myself and add to much code over from the source
qb_base.rb
file, I run the spec again to test my modifications. - Next, I spec the
generate_quickbooks_ruby_namespace
method. - Requiring
quickbooks-ruby
brings inActiveSupport
so camelcase works as expected. The othergenerate_quickbooks_ruby_namespace
method also passes so I move on. - It is time to tackle the tricky
oauth_client
method. - To accomplish the configure design and to keep the Gem code organized, I create a new file to handle this.




double()
and pass it in to get back to green.
accout
, I mean account
.
undefined method: camelcase
.
String.camelcase
method is from ActiveSupport
, which shouldn't be a problem to use because quickbooks-ruby
requires ActiveSupport
. The issue is that I don't have quickbooks-ruby
included as of yet.generate_quickbooks_ruby_namespace
spec is at 16:00 mark.


configuration.rb
is at 17:40 mark.

configuration.rb
goes inside of the base
folder.
$qb_oauth_consumer
variable.
extend Configuration
to base.rb
and re-running the spec I get an error uninitialized Constant Quickbooks::Base::Configuration

configuration.rb
. Remember to use require_relative
for code inside of the lib/
directory. The spec is now green.Great, I am half-way finished implementing the wily oauth_client method, which is a good place to stop for Part 2.
In the next installment, I will begin to integrate these configuration capabilities within the oauth_client
method. Please note that the last 2 screencasts in the series are already completed so check'em out:
- Pushed on 05/01/2014 by Christian