我正在尝试创建一个使用mysql2的插件,该插件允许从IRC与数据库进行通信。
我面临的问题是,如果没有崩溃,我就不能要求任何宝石进入插件。
require 'mysql2'
@client = nil
def weechat_init
Weechat.register('sql', 'Ninjex', '1.0', 'GPL3', 'Execute MySQL commands: /sql <query>', '', '')
Weechat.hook_command('sql', 'Execute MySQL database commands', '', '', '', 'sql', '')
return Weechat::WEECHAT_RC_OK
end
def sql(data, buffer, args)
buffer = Weechat.current_buffer
con_flag = '-c'
explode = args.split(' ')
if explode[0] == con_flag
#Weechat.buffer_set(buffer, 'localvar_set_con', explode.drop(1).join.strip)
con_info = explode.drop(1) # ["localhost", "username", "password", "database"]
hostname = con_info[0]
username = con_info[1]
password = con_info[2]
database = con_info[3]
@client = Mysql2::Client.new(:host => hostname, :username => username, :password => password, :database => database)
Weechat.print(buffer, "MySQL client created!")
else
row_count = 0
Weechat.command(buffer, "Sending query: #{args}")
sql_res = @client.query(args)
sql_res.each(:as => :array) {|r| row_count += 1; Weechat.command(buffer, "RESULT [#{row_count.to_s}]: "+r.to_s)}
return Weechat::WEECHAT_RC_OK
end
end
错误消息:
09:27:38 =!= | ruby: error while loading file "/home/ninjex/.weechat/ruby/sql.rb"
09:27:38 =!= | ruby: error: (eval):31:in `module_eval': cannot load such file -- mysql2 (LoadError)
09:27:38 =!= | ruby: error: from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
我注意到的一件事是:
ninjex@kali:~$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [i686-linux]
我使用的是ruby 2.1.1,错误输出显示它在/usr/lib/ruby/1.9.1/rubygems/
在交互式Ruby会话中或在常规Ruby脚本中加载mysql2
会成功。只有在尝试通过weechat应用此错误时才会收到错误。
任何帮助都会受到赞赏,如果它是宝石路径,我不知道如何更改正在加载的宝石的路径。
答案 0 :(得分:0)
我想出来了。 Weechat at it的当前版本不支持Ruby&gt; = 2.1.x
不幸的是,修复程序正在运行Weechat女巫Ruby&lt; = 1.9.3