cleaner 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,6 +15,9 @@ manage '~/Downloads' do
15
15
  move :avi, :to => '~/Movies/inbox'
16
16
  move %w(mp3 ogg), :to => '~/Music/inbox'
17
17
 
18
+ # label all files bigger than 100MB with red color (OS X only)
19
+ label :color => :red, :if => proc { |file| file.size > 100.megabytes }
20
+
18
21
  # Remove zip files if file without zip extension exists (uncompressed files)
19
22
  delete :zip, :if => proc { |file| File.exists?(file.path_without_ext) }
20
23
 
@@ -38,15 +41,85 @@ Generate sample configuration file (~/.cleaner.rb)
38
41
 
39
42
  Run cleaner in the background. By default it will run every 1 hour.
40
43
 
41
- $ cleaner start
44
+ $ cleaner start
42
45
 
43
46
  You can specify cleaning interval with "rails like" syntax: 20.minutes, 4.hours, 1.day
44
47
 
45
- $ cleaner start 4.hours
48
+ $ cleaner start 4.hours
46
49
 
47
50
  Stop cleaner daemon
48
51
 
49
- $ cleaner stop
52
+ $ cleaner stop
53
+
54
+
55
+ ## Available actions
56
+
57
+ - Deleting files
58
+ ```
59
+ delete :zip
60
+ ```
61
+ - Moving files
62
+ ```
63
+ move :pdf, :to => '~/Documents/pdfs'
64
+ ```
65
+ - Copying files
66
+ ```
67
+ copy :mp3, :to => '~/Documents/audio'
68
+ ```
69
+ - Labeling files with colors (OS X only). Available colors: :white, :orange, :red, :yellow, :blue, :purple, :green, :gray
70
+ ```
71
+ label :txt, :color => :blue
72
+ ```
73
+
74
+
75
+ ## Writing own actions
76
+
77
+ New actions can be added easily. All you need to do is implement #execute method.
78
+
79
+ Useful methods when implementing own actions:
80
+
81
+ - #files - array of filtered file paths
82
+ - #options - hash of options passed to action
83
+
84
+ ```ruby
85
+ # Here as example is label action which sets color label on files on OS X
86
+ module Cleaner
87
+ module Actions
88
+ class Label < Action
89
+ COLORS = {
90
+ :white => 0,
91
+ :orange => 1,
92
+ :red => 2,
93
+ :yellow => 3,
94
+ :blue => 4,
95
+ :purple => 5,
96
+ :green => 6,
97
+ :gray => 7,
98
+ }
99
+ def execute
100
+ code = COLORS[options[:color]]
101
+ files.each do |path|
102
+ script = %Q{tell application \\"Finder\\" to set label index of file (POSIX file \\"#{path}\\") to #{code}}
103
+ `osascript -e "#{script}"`
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ ```
110
+
111
+ ### Using custom action
112
+ Require action in your config file and use it as any other action.
113
+
114
+ ```ruby
115
+ require 'label.rb'
116
+ manage '/add-more-colors-to-your-files' do
117
+ # all avi files are labeled with green color
118
+ label :avi, :color => :green
119
+ # all files bigger than 100 megabytes are labeled with red color
120
+ label :color => :red, :if => proc { |file| file.size > 100.megabytes }
121
+ end
122
+ ```
50
123
 
51
124
  ## Contributions
52
125
 
@@ -57,7 +130,7 @@ To fetch & test the library for development, do:
57
130
  $ bundle
58
131
  $ bundle exec rspec
59
132
 
60
- If you wont to contribute, please:
133
+ If you want to contribute, please:
61
134
 
62
135
  * Fork the project.
63
136
  * Make your feature addition or bug fix.
data/lib/cleaner.rb CHANGED
@@ -5,6 +5,7 @@ require "cleaner/action"
5
5
  require "cleaner/actions/delete"
6
6
  require "cleaner/actions/move"
7
7
  require "cleaner/actions/copy"
8
+ require "cleaner/actions/label"
8
9
  require "cleaner/file_extension"
9
10
  require "cleaner/directory"
10
11
  require "cleaner/runner"
@@ -0,0 +1,23 @@
1
+ module Cleaner
2
+ module Actions
3
+ class Label < Action
4
+ COLORS = {
5
+ :white => 0,
6
+ :orange => 1,
7
+ :red => 2,
8
+ :yellow => 3,
9
+ :blue => 4,
10
+ :purple => 5,
11
+ :green => 6,
12
+ :gray => 7,
13
+ }
14
+ def execute
15
+ code = COLORS[options[:color]]
16
+ files.each do |path|
17
+ script = %Q{tell application \\"Finder\\" to set label index of file (POSIX file \\"#{path}\\") to #{code}}
18
+ `osascript -e "#{script}"`
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Cleaner
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Cleaner::Actions::Label do
4
+ before do
5
+ example_dir '/foo' do
6
+ %w(a.zip b.txt).each { |name| touch name }
7
+ end
8
+ Dir.chdir('/foo')
9
+ end
10
+
11
+ let(:label) { Cleaner::Actions::Label.new(%w(/foo/a.zip), :color => :red) }
12
+
13
+ it "should invoke labeling script for given file with color's code" do
14
+ command = "osascript -e \"tell application \\\"Finder\\\" to set label index of file (POSIX file \\\"/foo/a.zip\\\") to 2\""
15
+ label.should_receive(:`).with(command)
16
+ label.execute
17
+ end
18
+ end
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.5
4
+ version: 0.0.6
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-29 00:00:00.000000000 Z
12
+ date: 2012-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70199256123380 !ruby/object:Gem::Requirement
16
+ requirement: &70255426043020 !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: *70199256123380
24
+ version_requirements: *70255426043020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: filelist
27
- requirement: &70199256122960 !ruby/object:Gem::Requirement
27
+ requirement: &70255426042600 !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: *70199256122960
35
+ version_requirements: *70255426042600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &70199256122500 !ruby/object:Gem::Requirement
38
+ requirement: &70255426042140 !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: *70199256122500
46
+ version_requirements: *70255426042140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: daemons
49
- requirement: &70199256122080 !ruby/object:Gem::Requirement
49
+ requirement: &70255426041720 !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: *70199256122080
57
+ version_requirements: *70255426041720
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70199256121660 !ruby/object:Gem::Requirement
60
+ requirement: &70255426041300 !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: *70199256121660
68
+ version_requirements: *70255426041300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &70199256137600 !ruby/object:Gem::Requirement
71
+ requirement: &70255426040880 !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: *70199256137600
79
+ version_requirements: *70255426040880
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &70199256137180 !ruby/object:Gem::Requirement
82
+ requirement: &70255426040460 !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: *70199256137180
90
+ version_requirements: *70255426040460
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: timecop
93
- requirement: &70199256136760 !ruby/object:Gem::Requirement
93
+ requirement: &70255426040040 !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: *70199256136760
101
+ version_requirements: *70255426040040
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rb-fsevent
104
- requirement: &70199256136300 !ruby/object:Gem::Requirement
104
+ requirement: &70255426039580 !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: *70199256136300
112
+ version_requirements: *70255426039580
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: ruby_gntp
115
- requirement: &70199256135880 !ruby/object:Gem::Requirement
115
+ requirement: &70255426039160 !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: *70199256135880
123
+ version_requirements: *70255426039160
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"
@@ -146,6 +146,7 @@ files:
146
146
  - lib/cleaner/action.rb
147
147
  - lib/cleaner/actions/copy.rb
148
148
  - lib/cleaner/actions/delete.rb
149
+ - lib/cleaner/actions/label.rb
149
150
  - lib/cleaner/actions/move.rb
150
151
  - lib/cleaner/cli.rb
151
152
  - lib/cleaner/directory.rb
@@ -156,6 +157,7 @@ files:
156
157
  - spec/cleaner/action_spec.rb
157
158
  - spec/cleaner/actions/copy_spec.rb
158
159
  - spec/cleaner/actions/delete_spec.rb
160
+ - spec/cleaner/actions/label_spec.rb
159
161
  - spec/cleaner/actions/move_spec.rb
160
162
  - spec/cleaner/cli_spec.rb
161
163
  - spec/cleaner/directory_spec.rb
@@ -193,6 +195,7 @@ test_files:
193
195
  - spec/cleaner/action_spec.rb
194
196
  - spec/cleaner/actions/copy_spec.rb
195
197
  - spec/cleaner/actions/delete_spec.rb
198
+ - spec/cleaner/actions/label_spec.rb
196
199
  - spec/cleaner/actions/move_spec.rb
197
200
  - spec/cleaner/cli_spec.rb
198
201
  - spec/cleaner/directory_spec.rb