I get numerous "method redefined" warnings while running an application under Merb 0.9.3. Of course, I get this only when I run my script using the ruby -w option. Is there any way to get rid of the methods getting redefined (repeated loading of files) again and again?
Has this been resolved in Merb 1?
I don't know about your issue but Merb 1.0 works great for me. I also recommend using the latest version, there are a some bugs fixed even from 1.0.x.
Whether you get warnings may depend on which ruby version or warning level you use, as can be seen in this gist.
Or maybe they fixed stuff between 0.93 and 1.0 .
Related
ruby - 2.7.2
rails - 6.0
paperclip - 6.1.0
I am getting following warning in my console, while using paperclip gem with ruby 2.7.2
/Users/***/.rvm/gems/ruby-2.7.2/gems/paperclip-6.1.0/lib/paperclip/url_generator.rb:68: warning: URI.escape is obsolete
I know there are no maintainers for paperclip and it is deprecated but I cannot use active storage as I found paperclip is the easiest and best way for implementing attachments. How can I solve this warning ?
When you say "solve" the warning it's not quite clear what you might consider to be an acceptable solution. But you could:
a) Ignore the warning so long as you are sticking with these versions of Ruby and Rails, as it does not mean that anything is broken.
b) Write some code to suppress this specific warning, though I'd probably not do this as you'd increase the chance of forgetting about the issue, and then ending up with a more acute and time-sensitive problem down the road, if you upgraded part of your system to where URI.escape was no longer available.
c) Do what I've done in my Rails application, which is switch to a forked and maintained version of Paperclip, KT-Paperclip. If you wanted to update to the minimum version number that addresses these deprecation warnings, you'd choose 6.4.
Wellll the right answer is to do something better for your codebase as #UptDogTT suggests... but if you just need a get-it-done answer, this monkey patch adds URI.escape back using equivalent functionality. Add it as an initializer:
module URI
def self.escape url
URI::Parser.new.escape url
end
end
When I run my Rails app in WEBrick on Ubuntu, after upgrading to ruby-1.9.3-p327, I receive the following error:
[rake --tasks] /home/dsilver/.rvm/gems/ruby-1.9.3-p327/gems/em-dir-watcher-0.9.4/lib/em-dir-watcher.rb:7: Use RbConfig instead of obsolete and deprecated Config.
Any idea what's going on?
I've seen some posts connecting this to ImageMagick on Windows. I am on Ubuntu, but the app does use ImageMagick, and the ImageMagick functionality appears to have broken since the ruby upgrade from 1.9.2 to 1.9.3. I suspect a connection.
Thanks!
The Config module has been renamed to RbConfig. It’s still possible to use the old name, for backwards compatibility, but Ruby issues a warning if you do.
The em-dir-watcher gem uses the old name, and so you see the warning when it’s loaded. Someone has already sent a pull request fixing this, however the last update to em-dir-watcher was over two years ago so it might not get merged.
This is a warning that is generated, not an error, so your code should actually still work okay. If you really want to get rid of the warning you could add something like this before you require 'em-dir-watcher':
Object.send :remove_const, :Config
Config = RbConfig
This defines Config to be the same as RbConfig, which is what Ruby does anyway, but prevents the warning.
You can do (not recommended):
Go to the file ../lib/ruby/1.9/rbconfig/obsolete.rb
Edit the file, the change is commenting the line #warn ...
With that change, eliminated the advice "warn"
I am requiring the date library and I would expect the methods from this library to appear in the code completion list (and hence get the documentation inline). However nothing appears. Why so?
What RubyMine and Ruby version are you using? Please try 4.5 Release Candidate, everything works fine for me in that version
Using jruby 1.5.1
In a pretty simple cronjob that uses gems:
dbi
dbd-jdbc
jdbc-mysql
It also uses a pure Java JDBC driver in a jar, jtds-1.2.5.jar
Every time I run it, I get this in STDERR (which is annoying my cronjob monitoring utilty which thinks anything on stderr may be a problem)
/usr/local/rvm/gems/jruby-1.6.5.1/gems/deprecated-2.0.1/lib/deprecated.rb:199 warning: already initialized constant Deprecate
?? Any ideas? What's going on, what can I do about it? Not sure which of these gems depends on 'deprecated' library or what version, any easy way to find out?
Ah, okay, figured it out:
[rochkind#catalyst pull_reserves]$ gem dependency dbi
Gem dbi-0.4.5
deprecated (= 2.0.1)
But 0.4.5 is the most recent version of 'dbi', and it is locked to 2.0.1 of 'deprecated'. There is a more recent 3.0.0 version of deprecated.
Okay... not sure what my question is now, except if anyone can figure out more about what's going on, and what my actual options are. I guess report as an issue to 'dbi' gem, hoping it's got some maintainers who care, I dunno.
more update: Okay, and there's already an issue filed for this, from August. https://github.com/erikh/ruby-dbi/pull/8 Looks like the gem is not very maintained. sigh. sometimes ruby community really frustrates me.
I think this is what you need:
Suppress Warnings From Ruby
A comment there mentions the Rails method to silence warnings, but I don't think you're using Rails.
EDIT: I found slightly cleaner code here:
https://mislav.net/2011/06/ruby-verbose-mode/
EDIT: Note: A commenter below seems to disagree with the blog entry mentioned above. I'm not expressing agreement or disagreement with the blog entry and I'm not opinionating on the goodness or badness of Ruby's verbose mode, merely crediting the author for the slightly cleaner code I found there.
I think this is what you'd do:
module Kernel
def silence_warnings
with_warnings(nil) { yield }
end
def with_warnings(flag)
old_verbose, $VERBOSE = $VERBOSE, flag
yield
ensure
$VERBOSE = old_verbose
end
end unless Kernel.respond_to? :silence_warnings
# assuming the warning is being generated when the dbi module is loaded...
silence_warnings { require 'dbi' }
I need to get the jruby version for logging & debugging purposes.
I tried looking around JRuby.runtime for a version method, but I didn't find anything useful.
I also thought about using %x{jruby -v}. It works in most cases, except that there is always the possibility that more than one jruby version are installed, and I want to get the version of the currently running interpreter.
Did I miss something? Any suggestion?
You are looking for the global constant JRUBY_VERSION. This is a brother of VERSION, RUBY_ENGINE (not available under 1.8.x), RUBY_PLATFORM, etc.