Getting Warning from require savon in ruby - ruby

Ubuntu 18.04, ruby 2.5.1p57
I have a ruby program that I use on a number of different linux system. On one it produces a screed of warning from require 'savon'
elasticsearch#secesprd02:~$ ruby /usr/local/tools/dev/es-cluster/bin/send-json.rb -v --cluster test -c /usr/local/tools/dev/conf/conf.json -r name=ES-api-winlogbeat json/winlogbeat-api-key
/var/lib/gems/2.5.0/gems/akami-1.3.1/lib/akami/wsse.rb:99: warning: shadowing outer local variable - key
/var/lib/gems/2.5.0/gems/akami-1.3.1/lib/akami/wsse.rb:99: warning: shadowing outer local variable - v1
/var/lib/gems/2.5.0/gems/akami-1.3.1/lib/akami/wsse.rb:99: warning: shadowing outer local variable - v2
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59: warning: loading in progress, circular require considered harmful - /var/lib/gems/2.5.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb
from /usr/local/tools/dev/es-cluster/bin/send-json.rb:8:in `<main>'
from /usr/local/tools/dev/es-cluster/bin/send-json.rb:8:in `require_relative'
from /usr/local/tools/dev/common-library/lib/app-configure.rb:3:in `<top (required)>'
from /usr/local/tools/dev/common-library/lib/app-configure.rb:3:in `require_relative'
from /usr/local/tools/common-library/lib/SecretServer.rb:1:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /var/lib/gems/2.5.0/gems/savon-2.12.1/lib/savon.rb:26:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
...
The program runs without any obvious problems apart from the warings.
I have updated savon and akami gems but this made no difference.

The warning is caused due to
loading in progress, circular require considered harmful - /var/lib/gems/2.5.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb
That should not cause you any harm, given that the require keeps track of files already loaded, so the behaviour of your application should not be affected in any way.
A good overview on that can be found on this answer.
Under normal circumstances it's fine to require the same file twice, because require keeps a record of the libraries it has loaded and ignores a second call.
It looks as if you get this error if the library you are requiring
requires itself somehow, which is not something that require can cope
with -- the require operation presumably needs to complete before the
library is added to the list.
So if in a.rb you require b.rb and in b.rb you require a.rb. then when you write require "a" Ruby will
* start to require a.rb
* start to require b.rb
* start to require a.rb again and realise there is something terribly wrong.

Related

Why gem is not loaded: require gems gives error no such file

I installed gem 'ssh-net'. From the console I tried to require the gem like this:
irb(main):009:0* require 'ssh-net'
LoadError: cannot load such file -- ssh-net
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from (irb):9
from /home/csrhub/git/csrhub-api/bin/console:150:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:63:in `load'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:63:in `kernel_load'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:28:in `run'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:476:in `exec'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:30:in `dispatch'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:24:in `start'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/exe/bundle:46:in `block in <top (required)>'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/exe/bundle:34:in `<top (required)>'
from /usr/local/bin/bundle:23:in `load'
from /usr/local/bin/bundle:23:in `<main>'
Then I tried with a gem that works:
irb(main):023:0* require 'memcache'
=> false
I printed the gems locations:
csrhub#csrhub:~/git/csrhub-api$ bundle info 'net-ssh'
* net-ssh (5.2.0)
Summary: Net::SSH: a pure-Ruby implementation of the SSH2 client protocol.
Homepage: https://github.com/net-ssh/net-ssh
Path: /var/lib/gems/2.3.0/gems/net-ssh-5.2.0
csrhub#csrhub:~/git/csrhub-api$ bundle info 'memcache'
* memcache-client (1.8.5)
Summary: A Ruby library for accessing memcached.
Homepage: http://github.com/mperham/memcache-client
Path: /var/lib/gems/2.3.0/gems/memcache-client-1.8.5
csrhub#csrhub:~/git/csrhub-api$
I see that both gems are placed in the same directory. Why memcache is invokable and the ssh-net is not? What am I missing?
May be it has something to do with this ?
I installed gem 'ssh-net'.
No, you didn't. You installed the gem net-ssh, as you can clearly see in the output of bundle info that you posted:
csrhub#csrhub:~/git/csrhub-api$ bundle info 'net-ssh'
* net-ssh (5.2.0)
Summary: Net::SSH: a pure-Ruby implementation of the SSH2 client
Here you can see that the name of the gem is net-ssh and not ssh-net and that the name of the primary class is Net::SSH.
From the console I tried to require the gem like this:
irb(main):009:0* require 'ssh-net'
LoadError: cannot load such file -- ssh-net
The primary class in this gem is called Net::SSH. (It integrates in the Net namespace of the Ruby standard library, which has libraries like Net::FTP, Net::HTTP, Net::IMAP, Net::POP, Net::SMTP, and Net::Telnet.)
According to standard Ruby naming conventions, a class named Net::SSH should be located in a file named lib/ssh.rb. This is the file you need to require.
This is also shown in the very first line of the very first code sample of the very first page of the documentation:
require 'net/ssh'
I see that both gems are placed in the same directory. Why memcache is invokable and the ssh-net is not? What am I missing?
In 99.9% of all cases where a computer tells you it cannot find something, it is because that thing you told it to find is indeed not there. Computers are very, very good at finding things.
The same thing is the case here: you told Ruby
require 'ssh-net'
which means "go through each directory in the $LOAD_PATH and look for a file named ssh-net.rb". Such a file simply does not exist, ergo, you get a LoadError exception.

Ruby SketchUp LoadError if requiring correct files

I have the problem that I want to require a ruby file.
File overview:
ExcelConversion.rb
main.rb
/classes/excelReader.rb
/classes/elementIdentifier.rb
the main.rb has the header:
require classes/excelReader
require classes/elementIdentifier
the excelReader.rb has the header:
require 'rubyXL
the elementIdentifier.rb has the header:
require 'inifile
The problem is that if I execute the main.rb file, everything works fine. But, as soon as I write require main within the ExcelConversion file I get the error:
Error Loading File ExcelConversion.rb
Error: #<LoadError: cannot load such file -- rubyXL>
C:/Program Files (x86)/SketchUp/SketchUp 2018/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:54:in 'require'
C:/Program Files (x86)/SketchUp/SketchUp 2018/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:54:in 'require'
C:/shortenedPath/ExcelConversion/classes/ExcelReader.rb:1:in '<top (required)>'
C:/shortenedPath/ExcelConversion/main.rb:1:in 'require_relative'
C:/shortenedPath/ExcelConversion/main.rb:1:in '<top (required)>'
C:/shortenedPath/ExcelConversion.rb:4:in 'require_relative'
C:/shortenedPath/ExcelConversion.rb:4:in '<top (required)>'
I don't understand how that is even possible to throw an error, since the main.rb runs without problems.
Edit: Solution
I managed to find the solution. SketchUp needs to install the gems separately. This can be achieved through the Ruby Console and the command:
Gem.install "nameOfTheGem"
Then SketchUp stores a copy of the gem within it's own path and one can require it as usual.

Can you find out where a library was required from?

Background - in a Rails app, I'm seeing a bug in production where a file cannot find a class from the standard library; but in development, everything works fine. Presumably, some gem that I have in the development group but not the production group is requiring the necessary library, so the symbol is define for development but not for production.
Is there any way I can get Ruby to tell me where require was called for a given file?
(I'm deliberately not naming the offending library, because I don't want suggestions as to what might be requiring it; I want to know how I can find out myself)
To answer your direct question: patch/override the require method and get access to all the info you need.
app/config/environment.rb
# set up intrumentation
module RequireSpy
def require(*args)
puts "requiring #{args.join(', ')} from #{caller.first}"
super
end
end
Object.include(RequireSpy)
# init your rails app as usual
require File.expand_path('../application', __FILE__)
Rails.application.initialize!
Upon booting the rails app, it'll print a LOT of output:
requiring tilt from /Users/sergio/.gem/ruby/2.4.2/gems/sinatra-1.4.8/lib/sinatra/base.rb:3:in `<top (required)>'
requiring rack/protection from /Users/sergio/.gem/ruby/2.4.2/gems/sinatra-1.4.8/lib/sinatra/base.rb:4:in `<top (required)>'
requiring thread from /Users/sergio/.gem/ruby/2.4.2/gems/sinatra-1.4.8/lib/sinatra/base.rb:7:in `<top (required)>'
requiring time from /Users/sergio/.gem/ruby/2.4.2/gems/sinatra-1.4.8/lib/sinatra/base.rb:8:in `<top (required)>'
requiring uri from /Users/sergio/.gem/ruby/2.4.2/gems/sinatra-1.4.8/lib/sinatra/base.rb:9:in `<top (required)>'
You probably want to filter that.

Ruby 2.0.0 cannot load such file even though gem is installed

I've tried all of the other solutions people have talked about on here, but none of them have helped / applied.
I've written a Ruby script that requires the spreadsheet gem. The requiring works fine when I execute the script normally with ruby myscript.rb, but after running chmod +x myscript.rb, and then trying to run the program with ./myscript.rb I get the following error....
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- spreadsheet (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/parse.rb:2:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/interpreter.rb:1:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from ./pmcnp.rb:7:in `<main>'
The beginning of my script looks like this:
#!/usr/bin/ruby
require 'rubygems'
require 'spreadsheet'
If anyone has any ideas, I would really appreciate it.
From your answers to the comments, the ruby you're running normally - and therefore the one in which your gems are installed - is /Users/fcangialosi/.rbenv/shims/ruby. When you make the script executable, it uses the hint in the script to know which program to use to execute the script. In your case, you have:
#!/usr/bin/ruby
So that's using whichever ruby version you have installed in /usr/bin/ruby. In order to use your rbenv ruby instead of /usr/bin/ruby, change the shebang line to:
#!/usr/bin/env ruby

Ruby version errors / crack/xml in irb

Because of a bug with Float#round in Ruby 1.8.6, I was forced to upgrade to 1.9.3 and boy was that awful. After install, irb didn't work, complaining of a lack of psych. So I tried to install the gem, but it was angry that libyaml didn't exist, so I installed that. Not sure why they weren't included if they were so important.
Now when I use require 'Location.rb' (after having to specify that I actually do want to look in the current folder... using $LOAD_PATH), I get this error:
LoadError: cannot load such file -- crack/xml
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/ap-0.1.1/lib/ap.rb:2:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/tyre77/Dropbox/Aurora/GMap.rb:4:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
What does this mean? Also, when I execute ruby -v, it lists my version as 1.9.3p0 but this is dicking around in 1.9.1? All I want is my irb back and working!
It turned out that Ruby was looking for an XML parser called 'crack'. I don't know why it is referencing 2 versions of Ruby or why these dependencies aren't included in the Ruby build (since irb won't work without them) but to fix I installed the crack gem. sudo gem install crack
you can use
require_relative 'Location.rb'
or
require './Location.rb'

Resources