LoadError in gem

Hi,

I’m trying to package a library into a gem. I write the main file with
autoload, just like Rack’s.

module RenrenAPI

autoload :Authentication, “renren_api/authentication”
autoload :SignatureCalculator, “renren_api/signature_calculator”
autoload :HTTPAdapter, “renren_api/http_adapter”

end

But when I use the gem, I get a LoadError.

RenrenAPI::Authentication
LoadError: no such file to load – renren_api/authentication

The file does exist. Does anyone can tell me what the problem is with my
library, which does not happen to Rack.

Best regards,
Zhi-Qiang L.
[email protected]

On Wed, Apr 27, 2011 at 5:56 PM, Zhi-Qiang L. [email protected]
wrote:

end

But when I use the gem, I get a LoadError.

RenrenAPI::Authentication
LoadError: no such file to load – renren_api/authentication

The file does exist. Does anyone can tell me what the problem is with my
library, which does not happen to Rack.

You can check the load path:

p $:

before your code to check where Ruby is looking for requires. BTW,
Ruby 1.9 removed “.” from the load path.

Jesus.

On Apr 28, 2011, at 12:07 AM, Jess Gabriel y Galn wrote:

p $:

before your code to check where Ruby is looking for requires. BTW,
Ruby 1.9 removed “.” from the load path.

Jesus.

It shows that the lib directory is in the load path.
(/Users/siegfried/.rvm/gems/ruby-1.9.2-head/gems/renren-api-0.3.1/lib)

bogon% irb
ruby-1.9.2-head :001 > require “renren_api”
=> true
ruby-1.9.2-head :002 > RenrenAPI::Authentication
LoadError: no such file to load – renren_api/authentication
from (irb):2
from /Users/siegfried/.rvm/rubies/ruby-1.9.2-head/bin/irb:16:in
`’
ruby-1.9.2-head :003 > p $:
["/Users/siegfried/.rvm/gems/ruby-1.9.2-head/gems/renren-api-0.3.1/lib",
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1”,
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0”,
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby”,
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/vendor_ruby/1.9.1”,
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin10.6.0”,
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/vendor_ruby”,
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1”,
“/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/x86_64-darwin10.6.0”]

The directory structure is:

|~lib/
| |~renren_api/
| | |-authentication.rb
| | |-http_adapter.rb
| | -signature_calculator.rb |-renren_api.rb

The code I mentioned is the content of lib/renren_api.rb

Best regards,
Zhi-Qiang L.
[email protected]

What happens in your irb session if you type:

require “renren_api/authentication”

?

On Apr 27, 2011, at 11:56 PM, Zhi-Qiang L. wrote:

end
[email protected]

I find the problem is I made a wrong gemspec.

spec.files = Dir["{lib/*,spec/*}"] + %w{README}

It didn’t package the file under “lib/renren_api/”. To change it like
this will solve this problem.

spec.files = Dir["{lib/**/*,spec/*}"] + %w{README}

Thanks.

Best regards,
Zhi-Qiang L.
[email protected]

On Apr 28, 2011, at 1:54 AM, Brian C. wrote:

What happens in your irb session if you type:

require “renren_api/authentication”

?


Posted via http://www.ruby-forum.com/.

I receive a LoadError.

ruby-1.9.2-head :001 > require “renren_api/authentication”
LoadError: no such file to load – renren_api/authentication
from internal:lib/rubygems/custom_require:29:in require' from <internal:lib/rubygems/custom_require>:29:in require’
from (irb):1
from /Users/siegfried/.rvm/rubies/ruby-1.9.2-head/bin/irb:16:in
`’

Best regards,
Zhi-Qiang L.
[email protected]