file-watcher 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/watcher CHANGED
@@ -4,6 +4,7 @@ require 'base_app'
4
4
  require 'rb-inotify'
5
5
  require 'json'
6
6
  require 'file_watcher/watch_job'
7
+ require 'file_watcher/log_helper'
7
8
 
8
9
 
9
10
  #
@@ -17,6 +18,7 @@ require 'file_watcher/watch_job'
17
18
 
18
19
 
19
20
  class Watcher < BaseApp
21
+ include LogHelper
20
22
 
21
23
  def command_line_arguments
22
24
  super.concat [["w","watch-job-dir=","Directory of watch jobs.", true],
@@ -64,7 +66,7 @@ class Watcher < BaseApp
64
66
 
65
67
  WatchJob.registered_jobs.each do |job|
66
68
  @notifier.watch(job.watch_criteria[:target_dir], *job.watch_criteria[:events]) do |event|
67
- puts "got event: #{event}"
69
+ log "got event: #{event}"
68
70
  job.event_handler event
69
71
  end
70
72
  end
@@ -73,9 +75,9 @@ class Watcher < BaseApp
73
75
  handle_event event, make_flags_map(event.flags)
74
76
  end
75
77
 
76
- puts "Entering run loop."
78
+ log "Entering run loop."
77
79
  @notifier.run
78
- puts "Exited run loop."
80
+ log "Exited run loop."
79
81
  end
80
82
  end
81
83
 
@@ -0,0 +1,8 @@
1
+ require 'logger'
2
+ $Logger = Logger.new(STDOUT)
3
+
4
+ module LogHelper
5
+ def log msg, level='info'
6
+ $Logger.send( level, msg )
7
+ end
8
+ end
@@ -3,9 +3,11 @@ require 'cgi'
3
3
  require 'net/http'
4
4
  require 'net/https'
5
5
  require 'uri'
6
+ require File.join( File.dirname(__FILE__), 'log_helper')
6
7
 
7
8
  class WatchJob
8
9
  include WatchConfig
10
+ include LogHelper
9
11
  attr_accessor :watch_criteria, :watch_action
10
12
 
11
13
  @@registered_jobs = []
@@ -14,7 +16,6 @@ class WatchJob
14
16
  @@registered_jobs
15
17
  end
16
18
 
17
-
18
19
  def do_post event
19
20
  if watch_action[:http][:ssl]
20
21
  protocol = 'https'
@@ -33,37 +34,37 @@ class WatchJob
33
34
 
34
35
  body = watch_action[:http][:body].merge({ :args => watch_action[:http][:args].call().push(event.name) } )
35
36
 
36
- puts "URL: #{url}"
37
- puts "body: #{body.to_json}"
37
+ log "URL: #{url}"
38
+ log "body: #{body.to_json}"
38
39
 
39
- puts "Path: #{uri.path}"
40
- puts "URI: #{uri.inspect}"
41
- puts "Port: #{uri.port}"
40
+ log "Path: #{uri.path}"
41
+ log "URI: #{uri.inspect}"
42
+ log "Port: #{uri.port}"
42
43
 
43
44
  req = Net::HTTP::Post.new(uri.path)
44
45
  if watch_action[:http][:auth_user]
45
- puts "Setting auth..."
46
+ log "Setting auth..."
46
47
  req.basic_auth watch_action[:http][:auth_user], watch_action[:http][:auth_pass]
47
48
  end
48
49
 
49
50
  req.set_form_data({'body' => body.to_json })
50
- puts "SENDING: #{req.inspect}"
51
+ log "SENDING: #{req.inspect}"
51
52
  res = http.request(req)
52
- puts "Res: #{res.inspect}"
53
+ log "Res: #{res.inspect}"
53
54
  case res
54
55
  when Net::HTTPSuccess, Net::HTTPRedirection
55
56
  # OK
56
- puts "Req was ok"
57
+ log "Req was ok"
57
58
  else
58
59
  res.error!
59
60
  end
60
61
 
61
- puts "Response: #{res}"
62
+ log "Response: #{res}"
62
63
  end
63
64
 
64
65
  def event_handler event
65
- return unless event.name =~ watch_criteria[:file_glob]
66
-
66
+ return if watch_criteria[:file_glob] && !event.name =~ watch_criteria[:file_glob]
67
+
67
68
  if watch_action.keys.first == :http && watch_action[:http][:method] == :post
68
69
  return do_post event
69
70
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 6
9
- version: 1.0.6
8
+ - 7
9
+ version: 1.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul Santa Clara
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-15 00:00:00 -04:00
19
+ date: 2011-05-20 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,7 @@ files:
75
75
  - bin/watcher
76
76
  - lib/file_watcher/watch_config.rb
77
77
  - lib/file_watcher/watch_job.rb
78
+ - lib/file_watcher/log_helper.rb
78
79
  - README.textile
79
80
  has_rdoc: true
80
81
  homepage: https://github.com/relaynetwork/file-watcher