Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
6b8788c5
Commit
6b8788c5
authored
Feb 17, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converting logger and custom examples to new syntax
parent
8ec99b8a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
29 deletions
+29
-29
custom-watcher.rb
examples/custom-watcher.rb
+4
-4
logger.rb
examples/logger.rb
+5
-18
watcher-idea.rb
examples/watcher-idea.rb
+20
-7
No files found.
examples/custom-watcher.rb
View file @
6b8788c5
#!/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!
examples/logger.rb
View file @
6b8788c5
#!/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
examples/watcher-idea.rb
View file @
6b8788c5
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment