Access gem source code in Cloud 9 - cloud9-ide

I would like to open up and edit gem source code but I can't figure out how to in cloud 9.
Stack Overflow wants me to make this question longer but it really is that simple. Where is the damn code at?

You can find the location of gems by issuing one of the following commands:
rvm gemdir
gem environment (look for the gem path)

Cloud9 operates like any other terminal. The following is helpful if the gem has a unique name, as you will get fewer (better) results. I will use will_paginate for example:
sudo locate will_paginate
Since Cloud9 comes packaged with light permissions for the main user, you will benefit most from using sudo like above.
On my machine, the results include sub-directories in the two following locations:
/home/hstevens/.gem/ruby/gems/will_paginate-3.0.7
/usr/local/lib/ruby/gems/1.9.1/gems/will_paginate-3.0.7
Depending on whether you installed your gem as root or not, your results should include one or both of the above locations. (Actual paths may vary slightly.)

Related

How do I get rrdtool from homebrew to work with ruby on macOS

In our Rails application we do require 'RRD' at some point, but that results in a cannot load such file -- RRD. So obviously I used homebrew to install rrdtool, but the error remains.
The docs at https://oss.oetiker.ch/rrdtool/prog/rrdruby.en.html provide two options:
Either:
$: << '/path/to/rrdtool/lib/ruby/1.8/i386-linux'
require "RRD"
In my /opt/homebrew/Cellar/rrdtool/1.8.0/lib directory there's no mention of ruby, which is because of the --disable-ruby-site-install flag in the formula, because when I skip that flag I do actually get something: /opt/homebrew/Cellar/rrdtool/1.8.0/lib/ruby/2.6.0/universal-darwin21. However replacing the path/to string with this path still gives the error.
Or:
If you use the --ruby-site-install configure option you can drop the $: line since the RRDtool module will be found automatically.
Which is a little confusing (and probably outdated) because here it seems that ruby site install is disabled by default and you have to enable it proactively, whereas in the formula it's actually actively disabled.
Either way: both options didn't do the trick for me and if there's a solution without homebrew that's also fine.
For good measure: I'm on macOS Monterey
TL;DR
For the most part, I'd say that using a non-standard gem without a Ruby version manager is your main issue. There are instructions on the rrdruby site for installing it, but they don't follow typical conventions, so your mileage will vary.
Some Practical Suggestions
The require keyword is for gems, not binaries. You need to have an rrdtool-related gem installed, available to your Ruby instance (usually through a Bundler Gemfile or gemspec, or via the RUBYOPTS environment variable or your in-process Ruby $LOAD_PATH), and then require the correct name of the gem in your code. For example, using the older rrd-ffi gem:
# use sudo if you're installing it to the system,
# but I would strongly recommend a ruby version
# manager instead
gem install rrd-ffi
# in your Ruby class/module file
require "rrd"
For the gem you seem to be using, you have to compile the gem first to make it usable, and then ensure it's available in your Ruby $LOAD_PATH (or other gem lookup mechanism) before trying to require it. The error message you're seeing is basically telling you that a gem with that name is not available as called within any of the standard lookup locations.
Again, I'd suggest reading the build documentation for your gem, and then seeing if you can install it as part of a Bundler bundle, RVM gemset, or other non-system approach if you can. Otherwise, follow the directions for the rrdruby tool, which is not available as a standard Rubygems.org gem, in order to make it available before trying to require it.
Beware of Outdated or Non-Standard Gems
Most of the RRD gems I found were quite old; most were 7-8 years old or older, so their compatibility with current Rubies is potentially suspect. The gem-builder you're using is newer, but doesn't seem to be designed as a standard gem, so you need to build it and install it in a suitable lookup path before it can be required. Installing gems as system gems is almost always a bad idea, so I'd strongly recommend building it from source and using a ruby version manager rather than following the rrdtool author's atypical suggestions. YMMV.

How to require ruby gem from a specific location?

I am new to ruby, and is trying to write a git hook in ruby. I want to use the rugged gem in my script. The gem is already available in /opt/gitlab/embedded/service/gem/ruby/2.1.0/ as part of GitLab installation (Files List). How can I require that gem in my script?
I have tried $LOAD_PATH.unshift "/opt/gitlab/embedded/service/gem/ruby/2.1.0/" and then require "rugged", as mentioned in another stackoverflow answer, but it did not work.
Look carefully at how $LOAD_PATH is configured for each gem after you include it. Normally it's the full path to where the base gemname.rb is located, like in your case where rugged.rb is.
The way the $LOAD_PATH works is it scans through that list looking for rugged.rb and if it doesn't find it, moves on to the next possible location. You're specifying a directory which doesn't have that, so find the right path and fill that in, and you should be good.

can you get the Gem object to return a list of available gems in the path?

I am having issues getting my local gems to work on my web server. I keep getting no such file to load errors even though I have added my local gem dir to my .gemrc paths. I am hoping to find a way to at least see what gems I DO have access to.
I have tried adding my local gem path a couple ways including
Gem.path.push "/myHome/usrName/ruby/gems
with no luck. How do I do something like
Gem.available_gems.each do |g|
puts g
end
?
Try using Bundler. It manages your gems for you and lets your project know where to find them when employed properly. On production servers it can install a local copy of the gem so that you don't need to worry about setting up your path vars correctly.

How to Look at a Gem's Code

I have a Gem that I found at RubyForge and want to peek inside to see what code it contains. Is it possible to do this without installing the Gem on my system?
Also, if I use RVM on Mac OS X, does that at all change how my gems get installed (assuming I have one gemset)?
gem unpack unpacks the gem without installing it.
Gems on RubyGems usually have a link to the source code (most often on GitHub), in which case you can easily browse the code (I use this A LOT).
The "homepage" link also tends to link to the repository.
If all else fails, go to GitHub and search for the name of the gem (you may need to match up the authors to ensure it's the right repository for the gem).
Edit:
Just noticed that you asked about gems on Rubyforge. In which case my first step would be to check RubyGems. But otherwise you will need to download the gem and peek inside it (it's just a compressed archive so you can open it up in something like 7-zip).
Many gems have their source freely readable. The way that always works is to install it.
If you just want to browse the source; go to the gem on http://rubygems.org find your gem and use the "Source code" link.
In case of RubyForge you can find the links under the SCM link in the menu.

Getting started with gems and jeweler

With Jeweler I created a gem folder structure with ease.
However, I still have some questions:
Why are params like --gemcutter and --rubyforge still available for Jeweler. Aren't these replaced by RubyGems? Do I have to specify anything to create a gem for RubyGems?
In the Rakefile I have information about the gem, and when I run "rake install" it created a gemspec. Why is the same information in two places?
What is a manifest? Just read about it, haven't seen such file.
How do I make my gem callable from the shell once I have installed it, like rails. Cause right now it's just accessible through a Ruby script using require.
Should I use "jeweler release" or "gem push" to push my gem to RubyGems.org?
I have to specify "handle" when signing up in RubyGems. What is that?
Thanks.
jeweler was created before RubyGems became what it is, so it still reflects the split. I'm not sure when jeweler was last updated, either. (I think it also still recognizes building gems on Github, which is now disabled.)
I'm not sure I follow what you're saying. The specification in the Rakefile details what the spec that gets written should look like. The spec that gets written details what should be installed and how, I believe.
A manifest is a list of all the files that your gem should ship with. Not everyone uses one. See the hoe documentation for some pro-manifest discussion.
Many Ruby gems are only libraries. If you want yours to also have a program like jeweler or rake or rails that you can call, you have to write the callable program, put it in bin in your gem's layout and specify (in your gemspec) that it should be packaged and installed. See the Gem::Specification reference under files and executable.
Not sure. Consult both jeweler's docs and the docs for RubyGems.
You can give an email address or use a name (a 'handle', like I use Telemachus here), which is all they mean by 'handle'.
For the record, if you are just learning how to write gems, you do not need to upload your first attempts using RubyGems or anything like it. You can simply install the gem on your machine only.

Resources