maid 0.6.0.alpha.2 → 0.6.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/maid/maid.rb CHANGED
@@ -24,11 +24,11 @@ class Maid::Maid
24
24
  include ::Maid::Tools
25
25
 
26
26
  # Make a new Maid, setting up paths for the log and trash.
27
- #
27
+ #
28
28
  # Sane defaults for a log and trash path are set for Mac OS X, but they can easily be overridden like so:
29
- #
29
+ #
30
30
  # Maid::Maid.new(:log_device => '/home/username/log/maid.log', :trash_path => '/home/username/my_trash')
31
- #
31
+ #
32
32
  def initialize(options = {})
33
33
  options = DEFAULTS.merge(options.reject { |k, v| v.nil? })
34
34
 
@@ -56,7 +56,7 @@ class Maid::Maid
56
56
  @repeats = []
57
57
  @rules = []
58
58
  end
59
-
59
+
60
60
  # Start cleaning, based on the rules defined at rules_path.
61
61
  def clean
62
62
  unless @log_device.kind_of?(IO)
@@ -84,15 +84,15 @@ class Maid::Maid
84
84
  rescue LoadError => e
85
85
  STDERR.puts e.message
86
86
  end
87
-
87
+
88
88
  def watch(path, &rules)
89
89
  @watches << ::Maid::Watch.new(self, path, &rules)
90
90
  end
91
-
91
+
92
92
  def repeat(timestring, &rules)
93
93
  @repeats << ::Maid::Repeat.new(self, timestring, &rules)
94
94
  end
95
-
95
+
96
96
  # Daemonizes the process by starting all watches and repeats and joining
97
97
  # the threads of the schedulers/watchers
98
98
  def daemonize
@@ -102,13 +102,16 @@ class Maid::Maid
102
102
  all = @watches + @repeats
103
103
  all.each(&:run)
104
104
  trap("SIGINT") do
105
- all.each(&:stop)
106
- exit!
105
+ # Running in a thread fixes celluloid ThreadError
106
+ Thread.new do
107
+ all.each(&:stop)
108
+ exit!
109
+ end.join
107
110
  end
108
111
  sleep
109
112
  end
110
113
  end
111
-
114
+
112
115
  # Run a shell command.
113
116
  #--
114
117
  # Delegates to `Kernel.\``. Made primarily for testing other commands and some error handling.
@@ -18,9 +18,7 @@ module Maid
18
18
  end
19
19
 
20
20
  def define
21
- maid_instance.rule name do
22
- maid_instance.instance_eval(&task)
23
- end
21
+ maid_instance.rule(name, &task)
24
22
  self
25
23
  end
26
24
 
data/lib/maid/rule.rb CHANGED
@@ -1,6 +1,6 @@
1
- class Maid::Rule < Struct.new(:description, :instructions)
1
+ class Maid::Rule < Struct.new(:description, :instructions, :maid)
2
2
  # Follow the instructions of the rule.
3
3
  def follow(*args)
4
- instructions.call(*args)
4
+ maid.instance_exec(*args, &instructions)
5
5
  end
6
6
  end
@@ -1,17 +1,18 @@
1
1
  module Maid::RuleContainer
2
+ include ::Maid::Tools
2
3
  attr_reader :rules
3
-
4
+
4
5
  # initialize_rules
5
6
  def initialize_rules(&rules)
6
7
  @rules ||= []
7
8
  instance_exec(&rules)
8
9
  end
9
-
10
+
10
11
  # Register a rule with a description and instructions (lambda function).
11
12
  def rule(description, &instructions)
12
- @rules << ::Maid::Rule.new(description, instructions)
13
+ @rules << ::Maid::Rule.new(description, instructions, @maid || self)
13
14
  end
14
-
15
+
15
16
  # Follow all registered rules.
16
17
  def follow_rules(*args)
17
18
  @rules.each do |rule|
data/lib/maid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Maid
2
- VERSION = '0.6.0.alpha.2'
2
+ VERSION = '0.6.0.alpha.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.alpha.2
4
+ version: 0.6.0.alpha.3
5
5
  prerelease: 6
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: 2014-12-08 00:00:00.000000000 Z
12
+ date: 2014-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: escape
16
- requirement: &19806060 !ruby/object:Gem::Requirement
16
+ requirement: &17252340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 0.1.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *19806060
27
+ version_requirements: *17252340
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: thor
30
- requirement: &19804940 !ruby/object:Gem::Requirement
30
+ requirement: &17251340 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: 1.0.0
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *19804940
41
+ version_requirements: *17251340
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: deprecated
44
- requirement: &19803580 !ruby/object:Gem::Requirement
44
+ requirement: &17249860 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ~>
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: 3.0.0
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *19803580
52
+ version_requirements: *17249860
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: mime-types
55
- requirement: &19803040 !ruby/object:Gem::Requirement
55
+ requirement: &17249340 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '2.0'
61
61
  type: :runtime
62
62
  prerelease: false
63
- version_requirements: *19803040
63
+ version_requirements: *17249340
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: rubyzip
66
- requirement: &19802100 !ruby/object:Gem::Requirement
66
+ requirement: &17248660 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ~>
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: 1.1.0
72
72
  type: :runtime
73
73
  prerelease: false
74
- version_requirements: *19802100
74
+ version_requirements: *17248660
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: xdg
77
- requirement: &19801280 !ruby/object:Gem::Requirement
77
+ requirement: &17247680 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ~>
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: 2.2.3
83
83
  type: :runtime
84
84
  prerelease: false
85
- version_requirements: *19801280
85
+ version_requirements: *17247680
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: listen
88
- requirement: &19800320 !ruby/object:Gem::Requirement
88
+ requirement: &17246700 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ~>
@@ -93,10 +93,10 @@ dependencies:
93
93
  version: 2.7.9
94
94
  type: :runtime
95
95
  prerelease: false
96
- version_requirements: *19800320
96
+ version_requirements: *17246700
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rufus-scheduler
99
- requirement: &19786680 !ruby/object:Gem::Requirement
99
+ requirement: &17233580 !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
102
102
  - - ~>
@@ -104,10 +104,10 @@ dependencies:
104
104
  version: 3.0.6
105
105
  type: :runtime
106
106
  prerelease: false
107
- version_requirements: *19786680
107
+ version_requirements: *17233580
108
108
  - !ruby/object:Gem::Dependency
109
109
  name: fakefs
110
- requirement: &19785940 !ruby/object:Gem::Requirement
110
+ requirement: &17232800 !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
113
113
  - - ~>
@@ -115,10 +115,10 @@ dependencies:
115
115
  version: 0.4.2
116
116
  type: :development
117
117
  prerelease: false
118
- version_requirements: *19785940
118
+ version_requirements: *17232800
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: guard
121
- requirement: &19785300 !ruby/object:Gem::Requirement
121
+ requirement: &17232080 !ruby/object:Gem::Requirement
122
122
  none: false
123
123
  requirements:
124
124
  - - ~>
@@ -126,10 +126,10 @@ dependencies:
126
126
  version: 2.6.1
127
127
  type: :development
128
128
  prerelease: false
129
- version_requirements: *19785300
129
+ version_requirements: *17232080
130
130
  - !ruby/object:Gem::Dependency
131
131
  name: guard-rspec
132
- requirement: &19784740 !ruby/object:Gem::Requirement
132
+ requirement: &17231520 !ruby/object:Gem::Requirement
133
133
  none: false
134
134
  requirements:
135
135
  - - ~>
@@ -137,10 +137,10 @@ dependencies:
137
137
  version: 4.3.1
138
138
  type: :development
139
139
  prerelease: false
140
- version_requirements: *19784740
140
+ version_requirements: *17231520
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: rake
143
- requirement: &19784140 !ruby/object:Gem::Requirement
143
+ requirement: &17230980 !ruby/object:Gem::Requirement
144
144
  none: false
145
145
  requirements:
146
146
  - - ~>
@@ -148,10 +148,10 @@ dependencies:
148
148
  version: 10.3.2
149
149
  type: :development
150
150
  prerelease: false
151
- version_requirements: *19784140
151
+ version_requirements: *17230980
152
152
  - !ruby/object:Gem::Dependency
153
153
  name: redcarpet
154
- requirement: &19783380 !ruby/object:Gem::Requirement
154
+ requirement: &17230180 !ruby/object:Gem::Requirement
155
155
  none: false
156
156
  requirements:
157
157
  - - ~>
@@ -159,10 +159,10 @@ dependencies:
159
159
  version: 3.1.2
160
160
  type: :development
161
161
  prerelease: false
162
- version_requirements: *19783380
162
+ version_requirements: *17230180
163
163
  - !ruby/object:Gem::Dependency
164
164
  name: rspec
165
- requirement: &19782360 !ruby/object:Gem::Requirement
165
+ requirement: &17229180 !ruby/object:Gem::Requirement
166
166
  none: false
167
167
  requirements:
168
168
  - - ! '>='
@@ -173,10 +173,10 @@ dependencies:
173
173
  version: '3.0'
174
174
  type: :development
175
175
  prerelease: false
176
- version_requirements: *19782360
176
+ version_requirements: *17229180
177
177
  - !ruby/object:Gem::Dependency
178
178
  name: timecop
179
- requirement: &19781640 !ruby/object:Gem::Requirement
179
+ requirement: &17228420 !ruby/object:Gem::Requirement
180
180
  none: false
181
181
  requirements:
182
182
  - - ~>
@@ -184,10 +184,10 @@ dependencies:
184
184
  version: 0.7.0
185
185
  type: :development
186
186
  prerelease: false
187
- version_requirements: *19781640
187
+ version_requirements: *17228420
188
188
  - !ruby/object:Gem::Dependency
189
189
  name: yard
190
- requirement: &19780960 !ruby/object:Gem::Requirement
190
+ requirement: &17227860 !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements:
193
193
  - - ~>
@@ -195,10 +195,10 @@ dependencies:
195
195
  version: 0.8.4
196
196
  type: :development
197
197
  prerelease: false
198
- version_requirements: *19780960
198
+ version_requirements: *17227860
199
199
  - !ruby/object:Gem::Dependency
200
200
  name: rb-inotify
201
- requirement: &19780280 !ruby/object:Gem::Requirement
201
+ requirement: &17227100 !ruby/object:Gem::Requirement
202
202
  none: false
203
203
  requirements:
204
204
  - - ~>
@@ -206,10 +206,10 @@ dependencies:
206
206
  version: 0.9.0
207
207
  type: :development
208
208
  prerelease: false
209
- version_requirements: *19780280
209
+ version_requirements: *17227100
210
210
  - !ruby/object:Gem::Dependency
211
211
  name: rb-fsevent
212
- requirement: &19779560 !ruby/object:Gem::Requirement
212
+ requirement: &17226400 !ruby/object:Gem::Requirement
213
213
  none: false
214
214
  requirements:
215
215
  - - ~>
@@ -217,7 +217,7 @@ dependencies:
217
217
  version: 0.9.2
218
218
  type: :development
219
219
  prerelease: false
220
- version_requirements: *19779560
220
+ version_requirements: *17226400
221
221
  description: ! 'Be lazy: let Maid clean up after you. Think of it as "Hazel for hackers".'
222
222
  email:
223
223
  - hello@benjaminoakes.com