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
Hide 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
#!/usr/bin/env ruby
require
'./watcher-idea.rb'
require
'./watcher-idea.rb'
f
=
Noah
::
Watcher
.
new
do
|
f
|
Noah
::
Watcher
.
watch
do
f
.
pattern
=
"noah.Configuration*"
pattern
"noah.Configuration*"
f
.
destination
=
Proc
.
new
{
|
x
|
puts
x
}
destination
Proc
.
new
{
|
x
|
puts
x
}
run!
end
end
f
.
run!
examples/logger.rb
View file @
6b8788c5
#!/usr/bin/env ruby
#!/usr/bin/env ruby
$:
.
unshift
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
".."
,
"lib"
)))
require
'./watcher-idea.rb'
require
'rubygems'
require
'eventmachine'
require
'em-hiredis'
require
'logger'
require
'logger'
log
=
Logger
.
new
(
STDOUT
)
log
=
Logger
.
new
(
STDOUT
)
EventMachine
.
run
do
Noah
::
Watcher
.
watch
do
pattern
"noah.Application*"
# Passing messages...like a boss
destination
Proc
.
new
{
|
x
|
log
.
debug
(
x
)}
@channel
=
EventMachine
::
Channel
.
new
run!
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
}
"
)
}
end
end
examples/watcher-idea.rb
View file @
6b8788c5
require
'rubygems'
require
'rubygems'
require
'logger'
require
'eventmachine'
require
'eventmachine'
require
'em-hiredis'
require
'em-hiredis'
module
Noah
module
Noah
class
Watcher
class
Watcher
attr_accessor
:
pattern
,
:
destination
attr_accessor
:
my_pattern
,
:my_
destination
def
initialize
(
&
blk
)
def
self
.
watch
(
&
blk
)
@pattern
||=
"noah.*"
watcher
=
Noah
::
Watcher
.
new
@destination
||=
nil
watcher
.
instance_eval
(
&
blk
)
yield
(
self
)
if
block_given?
watcher
end
def
pattern
(
pattern
)
@my_pattern
=
pattern
end
def
destination
(
destination
)
@my_destination
=
destination
end
end
def
run!
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
end
private
private
def
run_watcher
(
dest
)
def
run_watcher
(
dest
)
watcher_log
=
Logger
.
new
(
STDOUT
)
EventMachine
.
run
do
EventMachine
.
run
do
watcher_log
.
info
(
"Starting Noah Watcher..."
)
watcher_log
.
info
(
"Filtering on messages:
#{
@my_pattern
}
"
)
channel
=
EventMachine
::
Channel
.
new
channel
=
EventMachine
::
Channel
.
new
r
=
EventMachine
::
Hiredis
::
Client
.
connect
r
=
EventMachine
::
Hiredis
::
Client
.
connect
r
.
psubscribe
(
@pattern
)
r
.
psubscribe
(
@
my_
pattern
)
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
channel
.
push
"
#{
message
}
"
channel
.
push
"
#{
message
}
"
end
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