-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwatchman.rb
37 lines (29 loc) · 1.09 KB
/
watchman.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'yaml'
require 'action_mailer'
require "#{File.expand_path(File.dirname(__FILE__))}/file_mailer"
settings = YAML::load_file './config.yml'
file_mtime_path = './file_mtime.txt'
ActionMailer::Base.smtp_settings = {
:user_name => settings['email']['user_name'],
:password => settings['email']['password'],
:domain => settings['email']['domain'],
:address => settings['email']['address'],
:port => settings['email']['port'],
:authentication => :plain,
:enable_starttls_auto => true
}
file_mtime_in = {}
file_mtime_in = YAML::load_file(file_mtime_path) if File.exist?(file_mtime_path)
file_mtime = {}
changed_content = []
Dir.glob(settings['watch']['files'].split(',')).each do |f|
file_mtime[f] = File.stat(f).mtime.to_i
if file_mtime_in.include?(f)
changed_content << f if file_mtime[f] != file_mtime_in[f] # File mtime is different
else
# New File
changed_content << f
end
end
File.open(file_mtime_path, 'w') { |file| file.write(file_mtime.to_yaml) }
FileMailer.experror(changed_content, settings['email']['to']).deliver_now if changed_content.length > 0