使RUBY Ocra适用于需要包含模块的库

时间:2013-05-23 22:00:00

标签: ruby mongodb executable ocra

我使用OCRA在Windows中创建了一个ruby可执行文件。我现在用它几年了,效果不错,没有抱怨。

但今天我在包含模块行的代码中创建并分发了一个包含Include模块的exe文件。

有没有更好的方法来编写代码或编译exe?

在下面的代码中,错误发生在 include Mongo 位置。如果我删除包含模块,那么代码不起作用

require 'all the libs including mongo'

###############################################################
#### to insert the program parameters and the data to mongodb
###############################################################
def writedatatomongodb(toinsert, sname, dname, collname, lfile)
#Sampele params to insert  {:command=>"get data", :servername=>"servname", :remotecommand=>"/user/home/somefile", :outputfile=>"filename123_YYYYMMDD.txt"}

include Mongo
@client = MongoClient.new(sname, 27017)
p "Copying parametrs to Mongodb"
#@client = MongoClient.new('myservername', 27017)
@db     = @client[dname] 
@coll   = @db[collname]

File.open(lfile, 'a'){ |f| f.puts "Copying params to Mongodb" }
id = @coll.insert(toinsert)
p "Copied parametrs to Mongodb"
rescue Exception => e 
File.open(lfile, 'a'){ |f| f.puts "Error occured: #{e}" }
end

0 个答案:

没有答案