Commit 6b8788c5 authored by John E. Vincent's avatar John E. Vincent

converting logger and custom examples to new syntax

parent 8ec99b8a
#!/usr/bin/env ruby
require './watcher-idea.rb'
f = Noah::Watcher.new do |f|
f.pattern = "noah.Configuration*"
f.destination = Proc.new {|x| puts x}
Noah::Watcher.watch do
pattern "noah.Configuration*"
destination Proc.new {|x| puts x}
run!
end
f.run!
#!/usr/bin/env ruby
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
require 'rubygems'
require 'eventmachine'
require 'em-hiredis'
require './watcher-idea.rb'
require 'logger'
log = Logger.new(STDOUT)
EventMachine.run do
# Passing messages...like a boss
@channel = EventMachine::Channel.new
r = EventMachine::Hiredis::Client.connect
r.psubscribe("noah.*")
r.on(:pmessage) do |pattern, event, message|
@channel.push "#{message}"
end
sub = @channel.subscribe { |msg|
log.debug("#{msg}")
}
Noah::Watcher.watch do
pattern "noah.Application*"
destination Proc.new {|x| log.debug(x)}
run!
end
require 'rubygems'
require 'logger'
require 'eventmachine'
require 'em-hiredis'
module Noah
class Watcher
attr_accessor :pattern, :destination
attr_accessor :my_pattern, :my_destination
def self.watch(&blk)
watcher = Noah::Watcher.new
watcher.instance_eval(&blk)
watcher
end
def pattern(pattern)
@my_pattern = pattern
end
def initialize(&blk)
@pattern ||= "noah.*"
@destination ||= nil
yield(self) if block_given?
def destination(destination)
@my_destination = destination
end
def run!
@destination.nil? ? (puts "Can't run without a destination") : run_watcher(@destination)
@my_destination.nil? ? (puts "Can't run without a destination") : run_watcher(@my_destination)
end
private
def run_watcher(dest)
watcher_log = Logger.new(STDOUT)
EventMachine.run do
watcher_log.info("Starting Noah Watcher...")
watcher_log.info("Filtering on messages: #{@my_pattern}")
channel = EventMachine::Channel.new
r = EventMachine::Hiredis::Client.connect
r.psubscribe(@pattern)
r.psubscribe(@my_pattern)
r.on(:pmessage) do |pattern, event, message|
channel.push "#{message}"
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment