unable to overcome the error PAC::ProgramError from my Rails application - ruby

I am new to Ruby. I have written a simple code :
...
pac = PAC.load(pacfilename)
return pac.find('http://www.google.com')
...
I am using gems
gem 'win32-service', '0.8.2', :platforms => :mingw
gem 'pac', "~> 1.0.0"
gem 'therubyracer', '0.11.0beta1', :platforms => :mingw
I am getting this following error :
PAC::ProgramError in Accounts#new
Showing G:/test/app/views/accounts/new.html.erb where line #6 raised:
Cannot call method 'lastIndexOf' of null
Extracted source (around line #6):
3: >
4:
5:
6: <%= getProxyServer %>
7:
8: <%= link_to 'Back', accounts_path %>
The relevant part of trace file
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:28:in rescue in block in call'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:22:inblock in call'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:57:in block in lock'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:55:incall'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:55:in Locker'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:55:inlock'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:21:in call'
pac (1.0.0) lib/pac/file.rb:18:infind'
app/helpers/accounts_helper.rb:46:in readPACfileData'
app/helpers/accounts_helper.rb:65:inreadPACfile'
app/helpers/accounts_helper.rb:83:in `getProxyServer'
What is the problem? I want to find out the proxyserverIP, if any, programmatically from the application and then use it for accessing websites. Any help?

Related

How to fix srb irb update error using gem Roo? or any option how to skip roo from type checking?

I have data pipeline that needs to work with excel xls. I use gem roo for reading xlsx and Push to some API endpoint. I'm starting the project use gem sorbet. Execute srb init and it works. But when I add gem roo, it becomes error.
How can I tell sorbet to skip checking roo gem only? or how can I fix this error?
Here my Gemfile list.
# frozen_string_literal: true
# typed: ignore
source 'https://rubygems.org'
gem 'activesupport', '< 5.1'
gem 'aws-record', '~> 2'
gem 'aws-sdk-s3', '~> 1'
gem 'faraday'
gem 'pry'
gem 'roo', '2.7.1'
gem 'rspec', group: :development
gem 'rubocop', group: :development
gem 'sorbet', group: :development
gem 'sorbet-runtime'
gem 'uuidtools'
And this is the error traceback from sorbet
Generating: sorbet/config
Reusing existing config file: sorbet/config
Generating: sorbet/rbi/sorbet-typed/
Generating: sorbet/rbi/gems/
Traceback (most recent call last):
14: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:234:in `<main>'
13: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:196:in `main'
12: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:118:in `init'
11: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:229:in `block in make_step'
10: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem-generator-tracepoint.rb:38:in `main'
9: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem-generator-tracepoint/tracer.rb:70:in `trace'
8: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem-generator-tracepoint.rb:39:in `block in main'
7: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/require_everything.rb:19:in `require_everything'
6: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/require_everything.rb:39:in `load_bundler'
5: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:579:in `require_all_gems'
4: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:579:in `each'
3: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:581:in `block in require_all_gems'
2: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:557:in `require_gem'
1: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:208:in `block in <class:GemLoader>'
/Users/ruby/.rvm/gems/ruby-2.5.1/gems/roo-2.7.1/lib/roo.rb:24:in `const_missing': Excel support has been extracted to roo-xls due to its dependency on the GPL'd spreadsheet gem. Install roo-xls to use Roo::Excel. (RuntimeError)
Here my lambda_function.rb
# frozen_string_literal: true
# typed: true
require 'aws-sdk-s3'
require 'json'
require 'pry'
require 'roo'
def lambda_handler(event:, context:)
response = {
statusCode: 200,
body: {
event: event['filename'],
context: context
}
}
response
end
event = {
event: {
operation: 'echo',
message: 'Hello world!',
filename: './penjualan_per_barang_190612145614.xlsx'
},
context: {}
}
lambda_handler(event)
I expect the srb init would return success. If there any help, it would be great.
This looks like a bug in Sorbet. I've created a fix for it here:
https://github.com/sorbet/sorbet/pull/1454
I'm not sure how you should work around it in the mean time other than not depend on 'roo'.

odd number list for Hash (SyntaxError), though I am using Ruby 1.8.7 hash declaration

I am trying to connect to Oracle database using 'activerecord' and Ruby 1.8.7 and getting below error on my Windows 7 machine. I searched around for this issue and came across 1.8 and 1.9 ruby declaration of 'Hash' however I am using Ruby 1.8.7 and I feel I am using correct hash declaration, please correct me if I am wrong.
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `gem_original_require': C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhancedadapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:917: odd number list for Hash (SyntaxError)
read_committed: "READ COMMITTED",
^
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:917: syntax error, unexpected ':', expecting '}'
read_committed: "READ COMMITTED",
^
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:917: syntax error, unexpected ',', expecting kEND
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:919: syntax error, unexpected '}', expecting kEND
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1471: dynamic constant assignment
DBMS_OUTPUT_BUFFER_SIZE = 10000 # can be 1-1000000
^
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1555: syntax error, unexpected $end, expecting kEND
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in `new_constants_in'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection'
from oracle_conn_testing.rb:5
This is how my code looks like
require 'rubygems'
gem "activerecord-oracle_enhanced-adapter"
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "oracle_enhanced",
:database => "someurl.net:1523/ABCAD",
:username => "testing1",
:password => "testing1")
class TestTable < ActiveRecord::Base
set_table_name "TABLE_NAME"
set_primary_key "ID"
end
TestTable.find(:all).each do |tt|
p tt
end
nac = TestTable.new()
Additional Information:
I have below gems on my machine :
* LOCAL GEMS *
actionmailer (2.3.4)
actionpack (2.3.4)
activerecord (2.3.4)
activerecord-oracle_enhanced-adapter (1.5.3)
activeresource (2.3.4)
activesupport (2.3.4)
json (1.8.1)
mysql (2.9.1 x86-mingw32)
rack (1.0.1)
rails (2.3.4)
rake (10.1.1)
ruby-oci8 (2.1.7 x86-mingw32)
rubygems-update (1.4.2)
I use below Rubygems version:
C:\Users\tester1>gem -v
1.4.2
I tried to connect using OCI8 and I was able to get response out of Oracle database so there is no connectivity issue from my machine.
irb(main):006:0> OCI8.new('testing1', 'testing1', 'someurl.net:1523/ABCAD').exec('select sysdate from dual') do |r| puts r.join(', ') end
Mon Mar 10 15:09:23 -0400 2014
=> 1
I used below link as my reference:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/oow10/rubyhol/instructions/rubyrails.htm
The error message shows that your error is coming from inside the activerecord-oracle_enhancedadapter gem, and that gem has a Ruby 1.9 style hash. You might find an older version of that gem that supports Ruby 1.8 and switch to that version.

Load Error : no such file to load -- watir/testcase after upgrading to watir 4.0.2

I just upgraded to watir 4.0.2 from watir 2.0.4 and i am getting the below error,
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:60:in `gem_original
_require': no such file to load -- watir/testcase (LoadError)
I searched about the error and was not able to find a solution to it.
Gem List
abstract (1.0.0)
actionmailer (3.2.8, 3.0.0)
actionpack (3.2.8, 3.0.0)
activemodel (3.2.8, 3.0.0)
activerecord (3.2.8, 3.0.0)
activeresource (3.2.8, 3.0.0)
activesupport (3.2.8, 3.0.0)
addressable (2.3.2)
akami (1.2.0)
arel (3.0.2, 1.0.1)
Ascii85 (1.0.1)
builder (3.0.0, 2.1.2)
bundler (1.0.22)
childprocess (0.3.6)
commandline (0.7.10)
commonwatir (4.0.0, 2.0.4)
erubis (2.7.0, 2.6.6)
ffi (1.1.5)
gyoku (0.4.6)
hike (1.2.1)
hoe (3.0.8)
httpi (0.9.7)
i18n (0.6.1, 0.4.2)
journey (1.0.4)
libwebsocket (0.1.5)
mail (2.4.4, 2.2.19)
mime-types (1.19, 1.18)
mini_magick (3.2.1)
multi_json (1.3.6)
mysql2 (0.3.11 x86-mingw32, 0.2.18 x86-mingw32, 0.2.6 x86-mingw32)
nokogiri (1.5.5 x86-mingw32)
nori (1.1.3)
pdf-reader (1.1.1)
polyglot (0.3.3)
rack (1.4.1, 1.2.5)
rack-cache (1.2)
rack-mount (0.6.14)
rack-ssl (1.3.2)
rack-test (0.6.2, 0.5.7)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rautomation (0.7.3, 0.6.3)
ruby-rc4 (0.1.5)
rubygems-update (1.8.24)
rubyzip (0.9.9)
s4t-utils (1.0.4)
savon (0.9.9)
selenium-webdriver (2.26.0)
sprockets (2.1.3)
sqlite3 (1.3.6 x86-mingw32)
sqlite3-ruby (1.3.3)
subexec (0.0.4)
text-format (1.0.0)
text-hyphen (1.0.2)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.33)
user-choices (1.1.6.1)
wasabi (2.1.0)
watir (4.0.2 x86-mingw32, 2.0.4)
watir-classic (3.3.0)
watir-webdriver (0.6.2)
websocket (1.0.6)
win32-api (1.4.8 x86-mingw32)
win32-process (0.6.6)
win32screenshot (1.0.7)
windows-api (0.4.2)
windows-pr (1.2.2)
xml-simple (1.1.1)
Ruby Version:ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
Any idea on this?
watir/testcase was removed from Watir recently. I can not find when it was removed, but the information is in CHANGES file or in Git history.
While it would probably be better to move away from Watir::TestCase, if you really need or want to use it, you can re-create it by copying the files from 3.0.
Assume you are using Ruby 1.8, which still has the test-unit gem installed by default, you can do the following:
1) Create a file named 'watir_testcase.rb' with the following code, which is basically a copy of the testcase.rb and assertions.rb file from 3.0:
require 'watir-classic'
require 'test/unit'
require 'test/unit/assertions'
module Watir
# Verification methods used by Watir::TestCase
module Assertions
include Test::Unit::Assertions
# Log a failure if the boolean is true. The message is the failure message logged.
# Whether true or false, the assertion count is incremented.
def verify boolean, message = 'verify failed.'
add_assertion
add_failure message.to_s, caller unless boolean
end
def verify_equal expected, actual, message=nil
full_message = build_message(message, <<EOT, expected, actual)
<?> expected but was
<?>.
EOT
verify(expected == actual, full_message)
end
def verify_match pattern, string, message=nil
pattern = case(pattern)
when String
Regexp.new(Regexp.escape(pattern))
else
pattern
end
full_message = build_message(message, "<?> expected to be =~\n<?>.", string, pattern)
verify(string =~ pattern, full_message)
end
end
end
module Test::Unit::Assertions
def assert_false(boolean, message=nil)
_wrap_assertion do
assert_block("assert should not be called with a block.") { !block_given? }
assert_block(build_message(message, "<?> is not false.", boolean)) { !boolean }
end
end
end
module Watir
# This is a 'test/unit' testcase customized to exeucte test methods sequentially by default
# and extra assertions
#
class TestCase < Test::Unit::TestCase
include Watir::Assertions
##order = :sequentially
def initialize name
throw :invalid_test if name == :default_test && self.class == Watir::TestCase
super
end
class << self
attr_accessor :test_methods, :order
def test_methods
#test_methods ||= []
end
def order
#order || ##order
end
def default_order= order
##order = order
end
def sorted_test_methods
case order
when :alphabetically then test_methods.sort
when :sequentially then test_methods
when :reversed_sequentially then test_methods.reverse
when :reversed_alphabetically then test_methods.sort.reverse
else raise ArgumentError, "Execute option not supported: #{#order}"
end
end
def suite
suite = Test::Unit::TestSuite.new(name)
sorted_test_methods.each do |test|
catch :invalid_test do
suite << new(test)
end
end
if (suite.empty?)
catch :invalid_test do
suite << new(:default_test)
end
end
return suite
end
def method_added id
name = id.id2name
test_methods << name if name =~ /^test./
end
def execute order
#order = order
end
end
public :add_assertion
end
end
2) In your test case files, change the:
require 'watir/testcase'
to require the newly created file:
require './watir_testcase'
(ensuring that the path is correct for wherever you saved the file)

How to setup Cucumber, Guard & Spork with Rails 3.1?

I'm trying to setup cucumber, rspec, guard and spork. I've got rspec working fine but cucumber crashes with the trace below.
I've try setting this up several times,
rails g cucumber:install --spork
spork cucumber --boostrap
etc... with no luck.
Gems:
rails (3.1.3)
guard (0.10.0)
guard-bundler (0.1.3)
guard-cucumber (0.7.4, 0.7.3)
guard-rails (0.0.3)
guard-rspec (0.6.0, 0.5.2)
guard-spork (0.5.1, 0.5.0)
cucumber (1.1.4)
cucumber-rails (1.2.1)
spork (0.9.0)
Running all features
Using the default profile...
Running tests with args ["--color", "--format", "pretty", "--require", "/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/guard-cucumber-0.7.4/lib/guard/cucumber/notification_formatter.rb", "--format", "Guard::Cucumber::NotificationFormatter", "--out", "/dev/null", "--require", "features", "features", "--format", "pretty", "--strict", "--tags", "~#wip", "features", "--no-profile"]...
Disabling profiles...
Exception encountered: #<RuntimeError: All but one formatter must use --out, only one can print to each stream (or STDOUT)>
backtrace:
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/configuration.rb:198:in `arrange_formats'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/configuration.rb:26:in `parse!'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/main.rb:55:in `configuration'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/main.rb:63:in `run_drb_client'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/main.rb:34:in `execute!'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/test_framework/cucumber.rb:24:in `run_tests'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:13:in `block in run'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/forker.rb:21:in `block in initialize'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/forker.rb:18:in `fork'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/forker.rb:18:in `initialize'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/matt/.rvm/gems/ruby-1.9.2-p290#alphascore/gems/spork-0.9.0/lib/spork/server.rb:48:in `run'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
Done.
I finally solved this, after playing around with flags passed to cucumber via my guardfile I was able to resolve conflicting flags and not overriding my cucumber.yml flags.
Working Guardfile
guard 'cucumber', :cli => "--drb" do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end
cucumber.yml
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~#wip"
%>
default: --drb <%= std_opts %> features
wip: --drb --tags #wip:3 --wip features
rerun: --drb <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~#wip
Conflicting Guardfile
guard 'cucumber', :cli => "--drb --color --format pretty" do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end

Issues with mysql2 with and ruby

Trying to get the gem mysql2 installed on ubuntu and I have tried all of the suggestions but I cannot get it to run. Here is the error in my application.
./bla.rb:65:in `post_init': undefined method `query' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/em/timers.rb:51:in `call'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/em/timers.rb:51:in `fire'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from ./bla.rb:234:in `start_server'
from ./bin/minibardaemon:15
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:254:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:254:in `start_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:263:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:263:in `start_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:295:in `start'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/controller.rb:73:in `run'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:197:in `run_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `catch_exceptions'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:196:in `run_proc'
I have installed all of the packages that are recommended and installed mysql2 via gem but still no luck.
libmysqlclient-dev
Is installed.
Im on Ubuntu.
# gem -v
1.3.7
# ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
Installing the gems
# gem install mysql
Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...
Installing RDoc documentation for mysql-2.8.1...
# gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysql2-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...
def create_mysql2
begin
mysql2 = Mysql2::EM::Client.new(
:username => DBUSER,
:password => DBPASS,
:host => DBHOST,
:port => DBPORT,
:socket => DBSOCKET,
:database => DBNAME
)
return mysql2
rescue Mysql2::Error => exception
$stderr.puts "Mysql Error: #{ exception.message }"
EventMachine::stop_event_loop
end
end
...
begin
mysql2 = create_mysql2
rescue Exception => ex
p ex
end
# query the db every x seconds.
EventMachine::add_periodic_timer(QUERY_INTERVAL) do
defer1 = mysql2.query "SELECT * FROM table LIMIT #{QUERY_LIMIT}"
doesn't realy look like mysql2 gem issue, could you please show 65'th line of you bla.rb file? And probably some number of lines that surround it.
it actually looks like your mysql2 client gets uninitialized for some reason.
I would advice to check if something like this works:
require 'mysql2'
mysql_client = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql_client.query('sql .. ')
if so, there's clearly an issue in your script

Resources