cleaner 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Cleaner [![Build Status](https://secure.travis-ci.org/wijet/cleaner.png)](http://travis-ci.org/wijet/cleaner)
2
2
  ---
3
3
 
4
- Tool for automatic management of directories on your disk with simple DSL.
4
+ Tool for automatic management of directories on your disk with simple DSL. Inspired by [Hazel](http://www.noodlesoft.com/hazel.php) app.
5
5
 
6
6
  ## Installation
7
7
 
@@ -16,7 +16,7 @@ manage '~/Downloads' do
16
16
  move %w(mp3 ogg), :to => '~/Music/inbox'
17
17
 
18
18
  # label all files bigger than 100MB with red color (OS X only)
19
- label :color => :red, :if => proc { |file| file.size > 100.megabytes }
19
+ label :color => :red, :bigger_than => 100.megabytes
20
20
 
21
21
  # Remove zip files if file without zip extension exists (uncompressed files)
22
22
  delete :zip, :if => proc { |file| File.exists?(file.path_without_ext) }
@@ -71,6 +71,26 @@ Stop cleaner daemon
71
71
  label :txt, :color => :blue
72
72
  ```
73
73
 
74
+ ## Available conditions
75
+
76
+ Conditions are used for more accurate files matching.
77
+
78
+ - :after - Matches files created given period time ago
79
+ ```
80
+ :after => 2.days
81
+ ```
82
+ - :if - Matches file for which block returns true. File object is passed to the block.
83
+ ```
84
+ :if => proc { |file| file.name =~ /foo/ }
85
+ ```
86
+ - :smaller_than - Matches files which are smaller than the given value
87
+ ```
88
+ :smaller_than => 10.megabytes
89
+ ```
90
+ - :bigger_than - Matches files which are bigger than the given value
91
+ ```
92
+ :bigger_than => 1.megabyte
93
+ ```
74
94
 
75
95
  ## Writing own actions
76
96
 
@@ -1,6 +1,6 @@
1
1
  module Cleaner
2
2
  class FileFilter
3
- CONDITIONS = [:after, :if]
3
+ CONDITIONS = [:after, :if, :smaller_than, :bigger_than]
4
4
 
5
5
  attr_reader :options
6
6
 
@@ -27,7 +27,12 @@ module Cleaner
27
27
 
28
28
  def filter_by_conditions(paths)
29
29
  paths.select do |path|
30
- after_condition?(path) && if_condition?(path)
30
+ [
31
+ after_condition?(path),
32
+ if_condition?(path),
33
+ smaller_than_condition?(path),
34
+ bigger_than_condition?(path)
35
+ ].all?
31
36
  end
32
37
  end
33
38
 
@@ -47,6 +52,16 @@ module Cleaner
47
52
  options[:if].call(file)
48
53
  end
49
54
 
55
+ def smaller_than_condition?(path)
56
+ return true unless options.has_key?(:smaller_than)
57
+ File.size(path) < options[:smaller_than]
58
+ end
59
+
60
+ def bigger_than_condition?(path)
61
+ return true unless options.has_key?(:bigger_than)
62
+ File.size(path) > options[:bigger_than]
63
+ end
64
+
50
65
  def path
51
66
  File.expand_path(options[:path])
52
67
  end
@@ -1,3 +1,3 @@
1
1
  module Cleaner
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -6,6 +6,7 @@ describe Cleaner::FileFilter do
6
6
  touch 'b-0.zip', :mtime => 10.days.ago
7
7
  touch 'b-1.zip', :ctime => 2.days.ago
8
8
  touch 'cc.txt', :ctime => 3.days.ago
9
+ touch 'big.txt', :content => "abc" * 10
9
10
  end
10
11
  end
11
12
 
@@ -33,7 +34,7 @@ describe Cleaner::FileFilter do
33
34
  filter(
34
35
  :if => proc { |file| file.name =~ /\w\w\.txt$/ },
35
36
  :pattern => nil
36
- ).filterize.should == %w(/foo/cc.txt)
37
+ ).filterize.should == %w(/foo/big.txt /foo/cc.txt)
37
38
  end
38
39
 
39
40
  it "should return files filtered by two conditions :if and :after" do
@@ -43,6 +44,20 @@ describe Cleaner::FileFilter do
43
44
  :pattern => nil
44
45
  ).filterize.should == %w(/foo/cc.txt)
45
46
  end
47
+
48
+ it "should return files filtered by :smaller_than condition" do
49
+ filter(
50
+ :smaller_than => 10.bytes,
51
+ :pattern => nil
52
+ ).filterize.should == %w(/foo/b-0.zip /foo/b-1.zip /foo/cc.txt)
53
+ end
54
+
55
+ it "should return files filtered by :bigger_than condition" do
56
+ filter(
57
+ :bigger_than => 20.bytes,
58
+ :pattern => nil
59
+ ).filterize.should == %w(/foo/big.txt)
60
+ end
46
61
  end
47
62
 
48
63
  describe "#search_pattern" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-31 00:00:00.000000000 Z
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70255426043020 !ruby/object:Gem::Requirement
16
+ requirement: &70289995222060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.14
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70255426043020
24
+ version_requirements: *70289995222060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: filelist
27
- requirement: &70255426042600 !ruby/object:Gem::Requirement
27
+ requirement: &70289995221640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70255426042600
35
+ version_requirements: *70289995221640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &70255426042140 !ruby/object:Gem::Requirement
38
+ requirement: &70289995221180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70255426042140
46
+ version_requirements: *70289995221180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: daemons
49
- requirement: &70255426041720 !ruby/object:Gem::Requirement
49
+ requirement: &70289995220760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70255426041720
57
+ version_requirements: *70289995220760
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70255426041300 !ruby/object:Gem::Requirement
60
+ requirement: &70289995220340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70255426041300
68
+ version_requirements: *70289995220340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &70255426040880 !ruby/object:Gem::Requirement
71
+ requirement: &70289995219920 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70255426040880
79
+ version_requirements: *70289995219920
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &70255426040460 !ruby/object:Gem::Requirement
82
+ requirement: &70289995219500 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70255426040460
90
+ version_requirements: *70289995219500
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: timecop
93
- requirement: &70255426040040 !ruby/object:Gem::Requirement
93
+ requirement: &70289995219080 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70255426040040
101
+ version_requirements: *70289995219080
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rb-fsevent
104
- requirement: &70255426039580 !ruby/object:Gem::Requirement
104
+ requirement: &70289995234980 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70255426039580
112
+ version_requirements: *70289995234980
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: ruby_gntp
115
- requirement: &70255426039160 !ruby/object:Gem::Requirement
115
+ requirement: &70289995234560 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70255426039160
123
+ version_requirements: *70289995234560
124
124
  description: ! " Cleaner is a small tool which helps you keep your directories clean.\n
125
125
  \ With simple DSL you define set of rules, which are then periodically executed
126
126
  against specified directory.\n"
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project: cleaner
190
- rubygems_version: 1.8.10
190
+ rubygems_version: 1.8.15
191
191
  signing_key:
192
192
  specification_version: 3
193
193
  summary: Tool for cleaning up your directories with friendly DSL