Wednesday, 7 August 2013

Building and requiring a gem

Building and requiring a gem

I built a gem called prawn_charts and can successfully require the module
that wraps all the classes (the classes are all in different files) and
the classes from the root directory of the project with this command in
irb:
require "./lib/prawn_charts.rb"
However, when I create the gem with $ rake build and $ rake install, cd to
my home directory, and require the gem in irb, I can only load the wrapper
module and not any of the individual classes:
~ $ irb
>> require 'prawn_charts'
=> true
>> PrawnCharts # this works
=> PrawnCharts
>> PrawnCharts::YLabelsDataCollector # don't know why this causes an error
NameError: uninitialized constant PrawnCharts::YLabelsDataCollector
Here is what the lib/prawn_charts.rb file looks like:
require 'prawn'
require_relative "./prawn_charts/version"
module PrawnCharts
end
# this loads PrawnCharts::YLabelsDataCollector
Dir["./lib/data_collectors/**/*.rb"].each {|file| require file }
Dir["./lib/renderers/**/*.rb"].each {|file| require file }
I also have this line in the gemspec file:
gem.files = `git ls-files`.split($/)
Thanks for the help.

No comments:

Post a Comment