Loading ruby packages outside rails Mac OS X - ruby

I've recently downloaded a ruby extension (Nokogiri) using the gem install command and I would like to use it outside rails, in a small script I'm writing. When I use it in rails, it works perfectly, but how to load it outside rails? Which files should I need to 'require'? (I don't seem to find the downloaded source)
Thank you if you can help me.

See this guide for using nokogiri.
Basically you just do
require 'rubygems'
require 'nokogiri'
and you're set up.
There's also some useful general information on using gems in ruby code here.

Related

Getting started with Ruby, Watir and Ruby Mine?

I want to automate testing of an e-commerce website. I installed Ruby, Watir, Gems and Ruby Mine.
Though I played around with RubyMine I could not figure how to start writing a simple script:
How do I start writing a simple script using RubyMine? I created a project. What is the next step? Do I have to create an rspec file now? And probably search for a sample program, and run it?
Can someone give me a sample of opening a website and maybe clicking a link so that I can see it running?
I would be grateful for simple documentation which helps me.
Did you even check Watir web site? There is plenty of documentation on how to get started there.
Here is the sample project that is using Cucumber and Watir to open a search page, send a query and verify the results.
Gemfile specifies the required gems, make sure they are installed or can be installed in your environment. If you are on Windows you need to install DevKit.

How to use Pygments.rb on Heroku?

My app uses a gem (pygments.rb) for syntax highlighting which requires access to pygments lib.
I cant get it to work on heroku as Python is not part of the rails build pack.
Any help/ link on how to link pygments?
Thanks
P.S. I've looked at TrevorTurk's method but looks like its made for albino rather than pygments.rb
Does anyone know better method to check that we're on heroku?
if ENV['HOME'] == '/app'
require 'rubypython'
RubyPython.start(:python_exe => "python2.6")
end
I found the solution from the link below.

Ruby Reporting through Ruport and other tools

I want to write a small reporting tool and looking to fetch data from MySQL. After searching I found a tool called as Ruport but I am not following where are it's binaries located. If not binaries than how to install it. It discusses the installation commands to install via gems, but where are the files located.
Secondly, do I have to create a Windows interface using fxRuby or wxRuby to work with it?
Are there other free reporting tools for Ruby?
It's probably a good idea to get a good book or two on Ruby, rather than asking these kind of questions, but here goes:
To install a gem, do
gem install gemname
To use it, put the following in Ruby code:
require "rubygems" # May not be necessary
require "gemname"
To find where your gem files are stored, do
gem env
And as for whether you need a GUI for ruport: can you try working that out yourself first?

How to get Shoes to use an already installed gem?

I have a ruby gem I created and installed and want to be able to use it in a Shoes app. As expected, Shoes reports it cannot find the gem, understandably since the gem is only installed for the standard ruby distribution. Can help pointing towards documentation explaining how to get Shoes to find this gem would be most appreciated.
Thanks.
Unless things have changed since _why left, this is not possible. Shoes is a separate Ruby installation and therefore needs its own gems.
To install a gem, you can do something like this at the beginning of your Shoes app:
Shoes.setup do
gem 'json'
end
Edit: there's also this previous SO thread:
Using Ruby libraries and gems with a Shoes app
U can think Shoes as a ruby-distro, like jruby or other rubies, it maintains its own gems.
therefore you will need to install it via shoes way like Michael Kohl said

Ruby: just-in-time gem installation?

Would it be possible to override the default "require" by adding automatic download-and-install code for any missing includes (provided that the missing include is published as a ruby gem).
Which would not work in situations where Ruby is not interfaced with a shell. But still I think it would be an interesting idea.
Is there such a mechanism in existence today?
Edit:Removed portion about password check. I just checked and gem install doesn't seem to require me to type my password.
You would be able to hijack require method so as gems are installed when an attempt is made to require them, but still you won't have access to newly installed gem in current process, because gem index has to be reloaded.
I understand the intentions but I think exercise might not be worth it.
When installing a fresh gem the gem will be installed in the GEM_HOME. If that is not writable then it will try in the user's home .gem directory (on *NIX at least).
You could certainly script this. In a way Rail's rake gems:build is just this. Just not on demand.
But, I would recommend against this. You could run into build, versioning, dependency and network issues. And probably security issues as well.
PS: Francis Hwang did something related a while ago, although only as a require, not a require gems.
http://fhwang.net/2005/11/01/urirequire-I-got-yer-Web-2-0-right-here
A better option would be to use bundler and distribute the required gems with the application.
It is also quite simple to write a script to bootstrap the installation of gems if you didn't
want to distribute them with your code (using the bundle install/check commands)

Resources