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.
generate_quickbooks_ruby_namespace
spec is at 16:00 mark.
configuration.rb
is at 17:40 mark.
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