toreriklinnerud-clean-files 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cleaner.rb +10 -2
- metadata +3 -4
data/lib/cleaner.rb
CHANGED
@@ -6,6 +6,10 @@ class Cleaner
|
|
6
6
|
VALID_INTERVALS = [:hourly, :daily, :weekly, :monthly, :yearly]
|
7
7
|
TIME_INTERVALS = [:hour, :day, :cweek, :month, :year]
|
8
8
|
|
9
|
+
SimpleFile = Struct.new(:path, :stat) do
|
10
|
+
delegate :ctime, :file?, :directory?, :to => :stat
|
11
|
+
end
|
12
|
+
|
9
13
|
def initialize(paths, options = {})
|
10
14
|
@paths = [paths].flatten
|
11
15
|
@options = options.reverse_merge(:threshold => 30.days.ago)
|
@@ -24,9 +28,13 @@ class Cleaner
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def files
|
31
|
+
if paths.any?{|path| path.include?('*')}
|
32
|
+
paths.map!{|path| Dir.glob(path)}
|
33
|
+
paths.flatten!
|
34
|
+
end
|
27
35
|
@_files ||= paths.map do |file_path|
|
28
36
|
begin
|
29
|
-
|
37
|
+
SimpleFile.new(file_path, File.stat(file_path))
|
30
38
|
rescue Errno::EOPNOTSUPP
|
31
39
|
nil
|
32
40
|
rescue Errno::ENOENT => e
|
@@ -34,7 +42,7 @@ class Cleaner
|
|
34
42
|
exit -2
|
35
43
|
end
|
36
44
|
end.compact.select do |file|
|
37
|
-
file.
|
45
|
+
file.file? || (options[:recursive] && file.directory?)
|
38
46
|
end.sort_by(&:ctime)
|
39
47
|
end
|
40
48
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toreriklinnerud-clean-files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tor Erik Linnerud
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
|
12
12
|
date: 2009-05-05 00:00:00 -07:00
|
13
|
-
default_executable:
|
13
|
+
default_executable: clean_files
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -20,13 +20,12 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 2.3.2
|
24
24
|
version:
|
25
25
|
description:
|
26
26
|
email: torerik.linnerud@alphasights.com
|
27
27
|
executables:
|
28
28
|
- clean_files
|
29
|
-
- clean_files
|
30
29
|
extensions: []
|
31
30
|
|
32
31
|
extra_rdoc_files:
|