LoadError in gem

Z

Zhi-Qiang Lei

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 Lei
(e-mail address removed)
 
J

Jesús Gabriel y Galán

Hi,

I'm trying to package a library into a gem. I write the main file with au= toload, just like Rack's.

module RenrenAPI

=A0autoload :Authentication, "renren_api/authentication"
=A0autoload :SignatureCalculator, "renren_api/signature_calculator"
=A0autoload :HTTPAdapter, "renren_api/http_adapter"

end

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

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.
 
Z

Zhi-Qiang Lei

my library, which does not happen to Rack.
=20
You can check the load path:
=20
p $:
=20
before your code to check where Ruby is looking for requires. BTW,
Ruby 1.9 removed "." from the load path.
=20
Jesus.
=20


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"
=3D> true=20
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 =
`<main>'
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/x=
86_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-darwin=
10.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 Lei
(e-mail address removed)
 
B

Brian Candler

What happens in your irb session if you type:

require "renren_api/authentication"

?
 
Z

Zhi-Qiang Lei

What happens in your irb session if you type:

require "renren_api/authentication"

?


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 `<main>'


Best regards,
Zhi-Qiang Lei
(e-mail address removed)
 
Z

Zhi-Qiang Lei

Hi,
=20
I'm trying to package a library into a gem. I write the main file with = autoload, just like Rack's.
=20
module RenrenAPI
=20
autoload :Authentication, "renren_api/authentication"
autoload :SignatureCalculator, "renren_api/signature_calculator"
autoload :HTTPAdapter, "renren_api/http_adapter"
=20
end
=20
But when I use the gem, I get a LoadError.
=20
LoadError: no such file to load -- renren_api/authentication
=20
The file does exist. Does anyone can tell me what the problem is with =
my library, which does not happen to Rack.
=20
Best regards,
Zhi-Qiang Lei
(e-mail address removed)
=20


I find the problem is I made a wrong gemspec.

spec.files =3D 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 =3D Dir["{lib/**/*,spec/*}"] + %w{README}

Thanks.

Best regards,
Zhi-Qiang Lei
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top