Accessing open-uri from the same directory

Hi,

I am have placed open-uri in the same directory as my application and I
am trying to include open-uri in my application using the require
attribute.

require File.dirname(FILE) + ‘/open-uri’

It throws the following error:

C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libs>ir test.rb
:0:in require': no such file to load -- uri (LoadError) from ./open-uri.rb:1 from test.rb:4 from :0:inrequire’

Thanks,

Hi Mohammad,

It happens because open-uri tries to load the uri library and it fails
to find it.

I couldn’t reproduce this behavior on my end…
The uri library should be located at
<path_to_merlin>\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\uri.rb
Is there a chance you’re changing the $LOAD_PATH array?

By the way, why would you want to copy the open-uri lib to your
application directory? The standard library folder is a part of the file
lookup paths, so no matter where your application is installed to, the
standard libraries (like open-uri) will still be available.

Shay.

Shay F.
http://www.ironshay.com
Follow me: http://twitter.com/ironshay

it can be useful when you want to deploy your application to systems
where
you don’t know if ironruby is installed etc. I’m doing the same for an
ironrubymvc application.
I still have to find a nicer solution to that maybe by reusing the
ironruby
configuration to make those paths configurable.

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

How can IronRuby work if it’s not installed?

it are just DLL’s you could host them inside your own application.ir.exe
also calls out to those libraries to do its work

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

You’re trying to use the File class to open URIs which is not supported.
Try open instead of File.open (and add require “open-uri” as well).

Shay.

Shay F.
http://www.ironshay.com
Follow me: http://twitter.com/ironshay

I am using the following code to scrape the webpage.

button = Button.new
button.Text = ‘Scrape URL’
button.Location = System::Drawing::Point.new(108,61)
button.click do |sender,args|

page = File.open(“http://www.azamsharp.com/Default.aspx”)
System::Windows::Forms::MessageBox.Show(page.read)

end

I get the following error message:

Invalid argument - URI formats are not supported

if you have openuri required
just remove the File that should work
or

uri = URI.parse(“http://somewhere.com/default.aspx”)
uri.open do |f|
#some logic here
end

or

you could just use

open(“http://somewhere.com/default.aspx”) do |f|

some logic here

end

taken from
http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/classes/OpenURI.html

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

I tried to add a require ‘open-uri’ but for some reason it is not able
to locate the open-uri files.

I have placed the open-uri in the libs folder and I said:

require ‘libs/open-uri’ but it is not able to locate the file.

If I put:

require ‘open-uri’

then it throws the error that error locating the file ‘open-uri’.

I used the following code:

def scrape_page()

uri = URI.parse(“http://somewhere.com/default.aspx”)

end

And now it throws the exception:

Unintitialzied constant Object: URI

Ivan Porto carrero wrote:

if you have openuri required
just remove the File that should work
or

uri = URI.parse(“http://somewhere.com/default.aspx”)
uri.open do |f|
#some logic here
end

or

you could just use

open(“http://somewhere.com/default.aspx”) do |f|

some logic here

end

taken from
http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/classes/OpenURI.html

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

what version of ironruby are you using?it looks like your search paths
are
messed up.

for example does require File.dirname(FILE) + ‘/libs/open-uri’ work?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Can you check if the open-uri.rb file exists in the folder:
<path_to_merlin>\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\

I have placed the open-uri file in the libs folder within the project.
But for some reason it blows up and says unable to locate open-uri file.

I tried with the path and got the following error:

require File.dirname(FILE) + ‘/libs/open-uri’

C:\IronRubyProjects\IronRubyTaskListApplication>ir main_form.rb
:0:in require': no such file to load -- uri (LoadError) from ./libs/open-uri.rb:1 from main_form.rb:4 from :0:in require’

Ivan Porto carrero wrote:

what version of ironruby are you using?it looks like your search paths
are
messed up.

for example does require File.dirname(FILE) + ‘/libs/open-uri’ work?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Here is the version:

C:\IronRubyProjects\IronRubyTaskListApplication>ir -v
IronRuby 0.5.0.0 on .NET 2.0.0.0

are you hosting ironruby in your application or are you using the ir
command
to run it?
Are the paths correct in ir.exe.config?

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

ok you also need the uri file
open-uri has a dependency on that file.

But still I think your search paths are messed up.
how does you config look like?
Where is ironruby located

did you pick a release or build from git?

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

I am using ir command to run it. It is all ruby code.

I went to the
C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8
folder and run the following code:

require ‘open-uri’

it asked for stringio (not sure why it was missing) so I placed it in
the 1.8 folder and ran again and it worked. But now when I use the same
files for my project libs/stringio.rb it does not work.

C:\IronRubyProjects\IronRubyTaskListApplication>ir main_form.rb
:0:in require': no such file to load -- uri (LoadError) from ./libs/open-uri.rb:1 from main_form.rb:4 from :0:inrequire’

Actually I checked using the ir.exe command line and it did not work
either. It seems like the

C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8

and

C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libs

contains duplicate rb files. One open-uri is for url and other is for
file system. I think the dependencies are messed up!

I have the exact same path in the ir.exe.config file. But I can only run
the open-uri if I am in the lib folder where the file is physically
located.

This is really strange!