I followed this tutorial to create a simple command-line gem and now I want to extend functionality with raad. Currently I have made the following changes after following the tutorial:
bin/zerp:
#!/usr/bin/env ruby
require 'zerp'
class Zerp
def start
Raad::Logger.debug 'zerp started'
EventMachine.run do
EventMachine.add_periodic_timer(1) do
Raad::Logger.info 'zerp is running'
end
end
end
def stop
EventMachine.stop
Raad::Logger.debug 'zerp stopped'
end
end
lib/zerp.rb:
require 'zerp/version'
require 'eventmachine'
require 'raad'
module Zerp
end
When I run the client from commandline I get the following error.
user@zenbook:~/git/zerp :) zerp
/home/user/.local/lib/ry/rubies/1.9.3-p194/lib/ruby/gems/1.9.1/gems/zerp-0.0.1/bin/zerp:5:in `<top (required)>': Zerp is not a class (TypeError)
from /home/user/.local/lib/ry/current/bin/zerp:23:in `load'
from /home/user/.local/lib/ry/current/bin/zerp:23:in `<main>'
user@zenbook:~/git/zerp :(
What is the proper approach to get this working?
This is a use-case I did not really look into when making Raad and only minor modifications will make it better integrate within a “executable” gem context. In the meantime you can use this workaround:
bin/zerp
zerp/lib/zerp.rb
zerp/lib/service.rb
zerp/lib/version
The way Raad works right now is that since the file requiring the raad gem is “zerp” then Raad tries to bootstrap using the “Zerp” class. To avoid conflicts you should use another module name than “Zerp” – I just picked “ZerpModule”.
I’ll try to make a fix shortly to have Raad integrate better in a gem context.