unpacking, editing and rebuilding ruby gem - ruby

I need to edit the contents of a ruby gem, call him a.gem.
I used gem unpack a.gem ,got the insides of it, and gem unpack --spec a.gem to get a .gemspec.
I've added a new file, updated the files: section of the .gemspec to include it. I've put a.gemspec inside the folder resulted from unpacking the gem.
Now I'm try to gem build a.gemspec, and I'm getting the following error:
Invalid gemspec in [logstash-output-jdbc-5.2.1-java.gemspec]: logstash-output-jdbc-5.2.1-java.gemspec:1: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('
--- !ruby/object:Gem::Specification
^
logstash-output-jdbc-5.2.1-java.gemspec:2: syntax error, unexpected ':', expecting end-of-input
name: logstash-output-jdbc
^
ERROR: Error loading gemspec. Aborting.
What am I doing something wrong? I'm not a ruby programmer and I just need to edit something there.

Try a simpler workflow
gem open my_gem
This will open the installed gem's source code in your EDITOR. Make your edits. Save, restart your app to see the effects.

A little late for OP, but these steps worked for me. Perhaps they'll help someone else:
gem spec pkg-1.2.3.gem --ruby > pkg.spec
gem unpack pkg-1.2.3.gem
mv pkg.spec pkg-1.2.3
cd pkg-1.2.3
gem build pkg.spec
Need the --ruby, otherwise the spec file is yaml.

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 pushing ruby gem to rubygems.org

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

kernel_require.rb:55:in `require': cannot load such file -- pry-byebug (LoadError)

I'm following along this tutorial on rspec using this page: Test First: Learn Ruby and using this Github repo: Github Repo for same course using rspec v3. My issue is that after cloning the repo, running bundle install in the root directory, and then rspec --init to create the spec_helper.rb file, I run rake spec and I end up with this error regarding a dependency: ~\.rbenv/versions/2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 'require': cannot load such file -- pry-byebug (LoadError)
The thing is that the pry-byebug gem is installed. I've uninstalled and reinstalled it, removed the repo and restarted, but no matter what I get this error, and I'm not sure how to resolve it.
I'm new to programming and to this site so any information I've left out I can easily provide.
EDIT: I eventually figured out my rookie mistake: there's a folder in the path that has a space in it. Changing that fixed the issue.
Spaces in the file path to the project cause problems, apparently. I edited the offending folder and rspec then worked as intended.

Install gem linecache19 : syntax error near unexpected token

I have tried to install a couple of ways but failed each time. Can you help? The outcome is always the same:
...
creating Makefile
make
generating trace_nums-i386-mingw32.def
/usr/bin/sh: -c: line 1: syntax error near unexpected token `Init_trace_nums.sub(/'
/usr/bin/sh: -c: line 1: `C:/Ruby193/bin/ruby -e \puts EXPORTS, + Init_trace_nums.sub(/\..*\z/,)\ > trace_nums-i386-mingw32.def'
make: *** [trace_nums-i386-mingw32.def] Error 258
I've seen several related posts, but none with this message. I'm using pik, in case that makes a difference.
I don't know how to interpret this error message. If I should be opening one of the gem source files and correcting its syntax, what file has this issue? (I've opened several in search.)
Specs: Windows 7, Ruby 1.9.3, Rails 3.2.3
What I've tried:
I have tried on the command line:
gem install linecache19
I have tried adding it to my Gemfile, then calling bundle install
gem 'linecache19'
I have tried downloading it from rubyforge and calling:
gem install linecache19-0.5.13.gem
I succeeded at this after almost a month. The solution was to use Ruby DevKit. Instructions for its installation (don't just unpack it) are here.

Error installing gems that use native extensions on Ubuntu, Ruby 1.9.2 via RVM

I get an error while trying to install the ffi gem:
~ - 16:54>gem i ffi
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
rake RUBYARCHDIR=/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/lib RUBYLIBDIR=/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/lib
/home/mdemare/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems.rb:370:in `bin_path': can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)
from /home/mdemare/.rvm/gems/ruby-1.9.2-p136/bin/rake:19:in `<main>'
Gem files will remain installed in /home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6 for inspection.
Results logged to /home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/gen/gem_make.out
I'm getting frequent errors of all kinds while installing gems with native extensions, so I assume that there's something broken with my Ubuntu installation, but I've no idea what. I'll post any information you need to diagnose the problem.
EDIT: When I cd to the ffi gem (mentioned in the second but last line), and run the rake line in line 6, I get "Could not find RubyGem rake-compiler".
After gem i rake-compiler, and run rake again, I get this:
configure: error: source directory already configured; run "make distclean" there first
make: *** [/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/build/x86_64-linux/ffi_c/1.9.2/libffi/.libs/libffi_convenience.a] Error 1
rake aborted!
Command failed with status (2): [make...]
Update:
These are my rake gemspecs:
~ - 10:59>find ~/.rvm/ -name 'rake-0.8.7.gemspec'
~/.rvm/gems/ruby-1.9.2-p136/specifications/rake-0.8.7.gemspec
~/.rvm/gems/ruby-1.9.2-p136#global/specifications/rake-0.8.7.gemspec
~/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/gems/1.9.1/specifications/rake-0.8.7.gemspec
The last one is where gem looks, but that gemspec is different from the first one, and doesn't include the executable. Copying the long one doesn't quite solve the problem though - I get a file not found for the rake executable.
This caused me a ton of aggravation at the Boston Hack Day when trying to install Vagrant (for which FFI is a dependency). I ended up wasting so much time that I switched machines to work around the problem.
After the fact, I found a hack that works (although I'm sure there's a better solution). The file that the error message is complaining about
~/.rvm/gems/ruby-1.9.2-p180/bin/rake
differs from other similar copies in that it's missing path setup stuff at the head, so I copied these lines from one of the files that had them:
[genericized per #danv's answer below. Thanks for the improvement!]
ENV['GEM_HOME']=ENV['GEM_HOME'] || '~/.rvm/gems/ruby-1.9.2-p180'
ENV['GEM_PATH']=ENV['GEM_PATH'] || '~/.rvm/gems/ruby-1.9.2-p180:~/.rvm/gems/ruby-1.9.2-p180#global'
ENV['PATH']='~/.rvm/gems/ruby-1.9.2-p180/bin:~/.rvm/gems/ruby-1.9.2-p180#global/bin:~/.rvm/rubies/ruby-1.9.2-p180/bin:' + ENV['PATH']
That fixed it for me. This was a new Ubuntu 10.10 install with no default Ruby installation (which could be part of the problem) and Ruby 1.9.2 installed using RVM. Lots of other gems installed fine, including those requiring native compilation, so the problem is something specific to FFI.
I had a similar problem, and a workaround at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=529663 helped me.
In short, try to install the gem with:
$ rake=/usr/bin/rake gem install ffi
#Tom Morris - Tried your method and it worked fine.
I inserted your path specs (modified - see below) into ~/.rvm/gems/ruby-1.9.2-p180/bin/rake after line 12.
I modified the path specs so they are generic using ~ for the user home:
ENV['GEM_HOME']=ENV['GEM_HOME'] || "~/.rvm/gems/ruby-1.9.2-p180"
ENV['GEM_PATH']=ENV['GEM_PATH'] || "~/.rvm/gems/ruby-1.9.2-p180:~/.rvm/gems/ruby-1.9.2-p180#global"
ENV['PATH']="~/.rvm/gems/ruby-1.9.2-p180/bin:~/.rvm/gems/ruby-1.9.2-p180#global/bin:~/.rvm/rubies/ruby-1.9.2-p180/bin:"+ ENV['PATH']
Thanks for finding this fix!
Thanks #Tim Morris and #danv, your answers / comments helped. I adjusted for my setup, which is based more towards a superuser environment. Now this is what /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rake looks like on my server:
require 'rubygems'
version = ">= 0"
ENV['GEM_HOME']=ENV['GEM_HOME'] || "/usr/local/rvm/gems/ruby-1.9.2-p180"
ENV['GEM_PATH']=ENV['GEM_PATH'] || "/usr/local/rvm/gems/ruby-1.9.2-p180:/usr/local/rvm/gems/ruby-1.9.2-p180#global"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end
gem 'rake', version
load Gem.bin_path('rake', 'rake', version)
The installer attempts to run rake but fails when it isn't found:
can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)
You need to install the rake gem: gem install rake.

Resources