Error pushing ruby gem to rubygems.org - ruby

This is my first time pushing a ruby gem to rubygems.org, and I keep getting this message when I push the gem:
`ERROR: While executing gem ... (Errno::EISDIR)
Is a directory # io_fread - tripadvisor-choice-cli-gem`
Any ideas? Let me know if I need to share anything else to shed light on the error. Thanks!

You must push a specific .gem file, not the directory in which the gem resides. That means in practice something like:
gem push my-gem-0.1.0.gem
Where that represents a very specific version of your gem. Normally you get that file from:
gem build my-gem.gemspec
Where that .gemspec file is either hand-authored or produced by some other process (e.g. rake).

Related

There was an error parsing 'Gemfile': An empty gem name is not valid

I have a student receiving an error when running 'bundle install'. Things look right as far as file structure and the gemspec file. However I can't quite understand what this error is wanting to tell me. There are a lot of posts out there about this error, however they pertain to specific gems like 'bcrypt' etc. I don't see much out there regarding gemspec.
[!] There was an error parsing 'Gemfile': An empty gem name is not valid. Bundler cannot continue.
# from /users/Kris/Desktop/Ruby-CLI-project/ruby_cli_project/Gemfile:7
# --------------------------------------------
#
> gamspec
#
# --------------------------------------------
If it is intended in Gemfile, the syntax should look like this
source 'https://rubygems.org'
gem 'rspec'
gem 'other-gem-name'
If you want to package your ruby as a gem, then create .gemspec file not Gemfile. gemspec doesn't need to be inserted inside Gemfile.

Error message when trying to create Gemfile

Can someone please break down the very very beginnings of how to run a Gemfile. I've read the Bundler webiste and it says I have to type "Gem Install Bundler" then source "https://rubygems.org". Everytime I do that I get an error message saying "Source is not recognised as an internal or external command, operable program or batch file. I've tried creating an empty gemfile first by typing "bundle init" but when I type my source, I get the error message. I also found some literature about telling it to look in github and tried to direct it to the actual project in github but it gave me the same error message.
I am completely new to coding but have to run some gems off a file in github to test my answers on some questions I've been given. There's a gemfile on the github page with this in it:
source 'https://rubygems.org'
gem rspec
gem pry
Any help for an absolute beginner is much appreciated.
You need to use source 'http://rubygems.org' not https:// which isn't supported yet
Run
gem install bundler
then you can author a Gemfile like
source 'https://rubygems.org'
gem 'rspec'
gem 'pry'
after this, you may run
bundle install
and as an outcome rspec and pry gems will be installed in your system.
You have more information about Gemfiles in Bundler official documentation.
Also, bear in mind that you are installing those gems system-wide, this might cause dependency problems and/or version problems if you have more projects where those gems are required. If that is the case, I recommend you using something to control Ruby versions and gemsets, for example RVM.

Specify source when using gem install with two sources

We do have an internal gem server (http://my.gem.server) and at this server we store the gem foo-1.2.3.gem
Our users add this server to the gem source. Our gem source looks like::
*** CURRENT SOURCES ***
https://rubygems.org/
http://my.gem.server/
So far it was working wonderfully.
Then someone at the community created the foo-0.0.1.gem
Now, when our internal clients perform a gem install, the foo-0.0.1.gem from the community is installed instead of our foo-1.2.3.gem
We have tried putting our source before the standard rubygems.org but still get the same results.
Does anyone know how can I tell gem install to get the gem from our internal source?
It would be even better if it would just hit the community source if it does not find on ours.
You have two options:
Specify the source in the command
gem install --source http://my.gem.server/ install foo
Edit the ${HOME}/.gemrc file
change
:sources:
- http://rubygems.org
- http://my.gem.server
to
:sources:
- http://my.gem.server
- http://rubygems.org
In your Gemfile, separate all gems into source blocks:
source "http://my.gem.server/" do
gem "foo"
end
source "https://rubygems.org/" do
gem "rails"
end
Having global source lines and/or using :source to disambiguate can open you to security issues, as these don't actually work the way you would expect:
http://collectiveidea.com/blog/archives/2016/10/06/bundlers-multiple-source-security-vulnerability/
Any internal gem name might get claimed on rubygems.org and suddenly get installed instead.
To add on to #ptierno's answer, if you have a Gemfile or .gemspec you can use the :source parameter.
gem 'foo', :source => 'http://my.gem.server'
Which gives priority to that server for that gem only.

How to contribute to a Ruby Gem

I am trying to contribute to a Ruby gem and I don't understand how to test a local gem without using a globally installed gem.
The gem I want to contribute to is a command line interface gem. I clone the gem into a directory then cd into that directory. However, when I run commands in the terminal when I'm in the cloned project directory it still uses the global gem. I've even run
gem uninstall gemname
then while inside the newly cloned gem directory I redo
gem install gemname.
No matter what changes I make to the gem, I can't see the results or what my contributions are doing because it's always running the global gem.
When I do try to type a command line command that is supposed to interact with the gem while in the cloned gem directory I get:
-bash: ~/.gem/ruby/2.1.0/bin/githubrepo: No such file or directory
I've done a ton of research but I'm just not getting it. Help?
gem install gemname will look for a .gem file in the current directory. If not found it will look for it on the web.
gem install --local /path/to/your/gemname.gem will allow you to target a particular directory. You may need to gem build gemname.gemspec first, so it has your changes.
Instead of doing this, I would write tests in the gem directory itself. It's likely that when running code in there, you can simply require 'gemname' in Ruby to get the gem functionality.
If it's a well-written gem, it should have tests already. They will most likely be in a directory called test or spec. Have a look at these tests and try to carry on in that style to test your changes. This will make your code changes far far more likely to be accepted as a pull request.

How to safely fix "invalid date format in specification" for webrobots-0.0.10.gemspec

For every gem execution I am receiving the following error:
Invalid gemspec in [...rvm/gems/ruby-1.9.2-p136/specifications/webrobots-0.0.10.gemspec]: invalid date format in specification: "2011-07-01 00:00:00.000000000Z"
I am not the webrobots maintainer and I can't uninstall that gem.
There is any safe action to fix this problem on a production server?
These days with Github and Bundler you don't have to be a maintainer in order to fix issues in the gems you're using. Just fork the project on Github, fix whatever issue is there, and them simply point Bundler at your fork. If it is a handy extension to the gem rather than just a hack for yourself you might also consider making a pull request to the original maintainer to roll your changes into the official gem.
Having said all of that, the issue that might cause this problem doesn't seem to be present in the gemspec of the 0.0.10 version of webrobots. This issue can occur when the date in the gemspec is in the format that you have in your error e.g.:
"2011-07-01 00:00:00.000000000Z"
Looking at a snippet of gemspec though we have:
s.authors = [%q{Akinori MUSHA}]
s.date = %q{2011-07-01}
s.description = %q{This library helps write robots.txt compliant web robots in Ruby.
So that seems to be correct. Another issue that has been known to cause this problem is a YAML parser issue, to fix you need to force the use of a particular YAML parser (psych). You need to define the following somewhere:
require 'yaml'
YAML::ENGINE.yamler = 'syck'
Lastly you might want to clean your local installation and then do a redeploy which may sort you out. Once again if you're using Bundler something like this:
gem update --system
rvm gemset empty mygemset
gem install bundler
gem install
Here is the way I fix the "invalid date format in specification" error:
1.) Go to the specifications folder located at:
/usr/local/lib/ruby/gems/1.8/specifications/
2.) Find the spec that is causing the problem.
3.) Change "s.date = %q{2011-05-21 00:00:00.000000000Z}" to "s.date = %q{2011-05-21}"
That's a WIN for me! Good Luck
You may be using old version of gem. See you current version gem -v.
Upgrade you gem to latest
gem update --system
And install you gem file again with new gem. gem install <gem-name> or bundle install

Resources