0

I'm trying to write a Ruby plasmoid for KDE. I need to use barely one rubygem. Whenever I write require 'dbus', it throw me and an error:

code/main.rb:6:in 'require': no such file to load -- dbus (LoadError) code/main.rb:6:in '<module:TestApp>' code/main.rb:5:in '<top (required)>' /usr/share/apps/plasma_scriptengine_ruby/applet.rb:177:in 'load' /usr/share/apps/plasma_scriptengine_ruby/applet.rb:177:in 'init' /usr/share/apps/plasma_scriptengine_ruby/applet.rb:201:in 'constraintsEvent': undefined method 'constraintsEvent' for nil:NilClass (NoMethodError) /usr/share/apps/plasma_scriptengine_ruby/applet.rb:201:in 'constraintsEvent': undefined method 'constraintsEvent' for nil:NilClass (NoMethodError)

Actually, normal "ruby main.rb" works well (regarding on "require" part), but testing plasmoid with "plasmoidviewer" fails. Note, that regular gems from standart Ruby installation works well, i.e. require 'Qt4' or require 'yaml' loads perfectly. I'm using Ruby 1.9.2p180 under Linux.

09:40 PM - UPDATE: Richard Dale, one of the QtRuby developers, just fixed this issue a few minutes ago. Next release of KDE will have patched version of QtRuby.

kyrylo
  • 1,691
  • 1
  • 15
  • 22
  • So your script works when called directly, but not from your test? How are you loading your file from your test file? – Dogbert May 22 '11 at 17:14
  • Yes, when called directly, everything's okay, regarding "requires". Everything loads as it should be. However, I don't understand your second question. I have an installed gem, called 'ruby-dbus', which invokes like that: `require 'dbus'`. It invokes perfectly in any ruby script, but not in the _main.rb_. No matter, what gem I require (except of default libraries), it will raise _LoadError_. I test my code with _plasmoidviewer_ utility, which has it's own representations on _main.rb_ file. Every plasmoid written in Ruby should require 'plasma_applet', which will be the first line of your code. – kyrylo May 22 '11 at 17:29

2 Answers2

0
   require 'find'
   require 'findUtils'

    Find.find(PATH_WHERE_GEM_IS_INSTALLED) do |path|
      if FileTest.directory?(path)
            $: << File.expand_path(path)
       if File.basename(path)[0] == ?. and File.basename(path) != '.'
          Find.prune
        else
          next
        end
      else
      end
    end

and after that you can do

require 'dbus'
Rizwan Sharif
  • 1,089
  • 2
  • 10
  • 20
  • I have no 'findUtils'. `require 'find'` works good. I think, there should be more clearer way to solve my problem. PATH_WHERE_GEM_IS_INSTALLED is like brute force, isn't it? :-) – kyrylo May 22 '11 at 17:37
0

Have you tried this:

require 'rubygems'

?

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
  • Yes, I have. By the way, assuming, that you're a Ruby 1.9 user, automatically means, that rubygems already included by default (try `require 'rubygems'` in irb session, and you'll see, that it will return `false`). – kyrylo May 22 '11 at 16:49