broom 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +9 -10
- data/Rakefile +4 -4
- data/lib/broom.rb +11 -5
- metadata +5 -18
data/README.markdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Broom
|
2
|
-
|
1
|
+
# Broom
|
2
|
+
|
3
3
|
A simple module to help monitor a directory for new files and perform an action
|
4
4
|
on each new file. Broom periodically sweeps a directory, caching each file and its
|
5
5
|
last modification time. After each sweep, Broom iterates through the cache and
|
@@ -14,13 +14,12 @@ using the 'success_dir' and 'failure_dir' options.
|
|
14
14
|
/path/to/directory/_success
|
15
15
|
/path/to/directory/_failure
|
16
16
|
|
17
|
-
Installation
|
18
|
-
|
19
|
-
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
gem install broom
|
20
20
|
|
21
|
-
|
22
|
-
========
|
21
|
+
## Example
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
Broom.sweep('/dropbox') do |f|
|
24
|
+
Resque.enqueue(Job, "#{File.dirname(f)}/_success/#{File.basename(f)}")
|
25
|
+
end
|
data/Rakefile
CHANGED
@@ -5,14 +5,14 @@ $:.unshift(File.dirname(__FILE__))
|
|
5
5
|
require 'lib/broom'
|
6
6
|
|
7
7
|
desc "Publish gem and source."
|
8
|
-
task :publish => :
|
8
|
+
task :publish => :gem do
|
9
9
|
sh "gem push broom-#{Broom::VERSION}.gem"
|
10
10
|
sh "git tag v#{Broom::VERSION}"
|
11
11
|
sh "git push origin v#{Broom::VERSION}"
|
12
12
|
sh "git push origin master"
|
13
13
|
end
|
14
14
|
|
15
|
-
desc "Build gem."
|
16
|
-
task :
|
17
|
-
|
15
|
+
desc "Build broom gem."
|
16
|
+
task :gem do
|
17
|
+
sh "gem build broom.gemspec"
|
18
18
|
end
|
data/lib/broom.rb
CHANGED
@@ -7,7 +7,7 @@ end
|
|
7
7
|
|
8
8
|
module Broom
|
9
9
|
|
10
|
-
VERSION = '0.3.
|
10
|
+
VERSION = '0.3.2'
|
11
11
|
|
12
12
|
class Directory
|
13
13
|
|
@@ -37,20 +37,26 @@ module Broom
|
|
37
37
|
extend self
|
38
38
|
|
39
39
|
def sweep(path, options={}, &block)
|
40
|
+
options[:log] ||= true
|
41
|
+
|
40
42
|
dir = Directory.new(path, options)
|
43
|
+
log = lambda do |msg|
|
44
|
+
puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}: #{msg}" if options[:log]
|
45
|
+
end
|
46
|
+
|
41
47
|
loop do
|
42
48
|
cache = dir.entries
|
43
|
-
sleep
|
44
|
-
|
49
|
+
sleep(options[:sleep] || 1)
|
50
|
+
|
45
51
|
cache.each do |file, modified_at|
|
46
52
|
next if modified_at != File.mtime(file)
|
47
53
|
begin
|
48
54
|
yield(file)
|
49
55
|
rescue Object => boom
|
50
|
-
|
51
|
-
puts boom.backtrace.join("\n")
|
56
|
+
log.call("failure: #{File.basename(file)} [#{boom.message}]")
|
52
57
|
FileUtils.mv(file, dir.failure_dir)
|
53
58
|
else
|
59
|
+
log.call("success: #{File.basename(file)}")
|
54
60
|
FileUtils.mv(file, dir.success_dir)
|
55
61
|
end
|
56
62
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: broom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 1
|
10
|
-
version: 0.3.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.2
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Daniel Johnston
|
@@ -15,8 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
13
|
+
date: 2011-05-29 00:00:00 Z
|
20
14
|
dependencies: []
|
21
15
|
|
22
16
|
description: " A small module for watching a directory for new files.\n"
|
@@ -32,8 +26,7 @@ files:
|
|
32
26
|
- LICENSE
|
33
27
|
- Rakefile
|
34
28
|
- lib/broom.rb
|
35
|
-
|
36
|
-
homepage: http://github.com/djohnston/broom
|
29
|
+
homepage: https://github.com/drfeelngood/broom
|
37
30
|
licenses: []
|
38
31
|
|
39
32
|
post_install_message:
|
@@ -46,23 +39,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
39
|
requirements:
|
47
40
|
- - ">="
|
48
41
|
- !ruby/object:Gem::Version
|
49
|
-
hash: 3
|
50
|
-
segments:
|
51
|
-
- 0
|
52
42
|
version: "0"
|
53
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
44
|
none: false
|
55
45
|
requirements:
|
56
46
|
- - ">="
|
57
47
|
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 0
|
61
48
|
version: "0"
|
62
49
|
requirements: []
|
63
50
|
|
64
51
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.
|
52
|
+
rubygems_version: 1.7.2
|
66
53
|
signing_key:
|
67
54
|
specification_version: 3
|
68
55
|
summary: Simple file picker-upper
|