watch_tower 0.0.1.beta9 → 0.0.1.beta10

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,9 +9,14 @@ module WatchTower
9
9
 
10
10
  VIM_EXTENSION_PATH = File.join(EDITOR_EXTENSIONS_PATH, 'watchtower.vim')
11
11
 
12
+ # Set the attributes read/write of this class.
13
+ attr_reader :version
14
+
12
15
  def initialize
13
16
  # Get the list of supported vims
14
17
  supported_vims
18
+ # Fetch the version
19
+ @version ||= fetch_version
15
20
  end
16
21
 
17
22
  # Return the name of the Editor
@@ -21,33 +26,6 @@ module WatchTower
21
26
  "ViM"
22
27
  end
23
28
 
24
- # Return the version of the editor
25
- #
26
- # @return [String] The editor's version
27
- def version
28
- return if @version
29
-
30
- @version = nil
31
- if is_running?
32
- editor_command = editor
33
- begin
34
- Open3.popen2 "#{editor_command} --version" do |stdin, stdout, wait_thr|
35
- parsed_stdout = stdout.read.scan(/^VIM - Vi IMproved (\d+\.\d+).*/)
36
- LOG.info "#{__FILE__}:#{__LINE__ - 1}: Parsed vim --version: #{parsed_stdout.inspect}"
37
- @version = parsed_stdout.try(:first).try(:first)
38
- end
39
-
40
- raise VimVersionNotPrinted if @version.nil?
41
- rescue VimVersionNotPrinted
42
- if editor_command =~ /gvim|mvim/
43
- editor_command = WatchTower.which('vim')
44
- retry
45
- end
46
- end
47
- end
48
- @version
49
- end
50
-
51
29
  # Is it running ?
52
30
  #
53
31
  # @return [Boolean] Is ViM running ?
@@ -85,6 +63,31 @@ module WatchTower
85
63
  end
86
64
 
87
65
  protected
66
+ # Fetch the version
67
+ #
68
+ # @return [String] The editor's version
69
+ def fetch_version
70
+ if editor
71
+ editor_command = editor
72
+ begin
73
+ version = nil
74
+ Open3.popen2 "#{editor_command} --version" do |stdin, stdout, wait_thr|
75
+ parsed_stdout = stdout.read.scan(/^VIM - Vi IMproved (\d+\.\d+).*/)
76
+ LOG.info "#{__FILE__}:#{__LINE__ - 1}: Parsed vim --version: #{parsed_stdout.inspect}"
77
+ version = parsed_stdout.try(:first).try(:first)
78
+ end
79
+
80
+ raise VimVersionNotPrinted if version.nil?
81
+ rescue VimVersionNotPrinted
82
+ if editor_command =~ /gvim|mvim/
83
+ editor_command = WatchTower.which('vim')
84
+ retry
85
+ end
86
+ end
87
+ end
88
+ version || 'Not installed'
89
+ end
90
+
88
91
  # Return a list of supported vim commands
89
92
  #
90
93
  # @return [Array] A list of supported vim commands.
@@ -30,12 +30,13 @@ module WatchTower
30
30
  # Iterate over the files to fill the database
31
31
  files_paths.each do |file_path|
32
32
  begin
33
- next if file_path =~ IGNORED_PATHS
34
33
  next unless file_path
35
- next unless File.exists?(file_path)
36
- next unless File.file?(file_path)
34
+ LOG.debug("#{__FILE__}:#{__LINE__}: Ignoring #{file_path}") and next if file_path =~ IGNORED_PATHS
35
+ LOG.debug("#{__FILE__}:#{__LINE__}: #{file_path} does not exist.") and next unless File.exists?(file_path)
36
+ LOG.debug("#{__FILE__}:#{__LINE__}: #{file_path} is not a file") and next unless File.file?(file_path)
37
37
  # Get the file_hash of the file
38
38
  file_hash = Digest::SHA1.file(file_path).hexdigest
39
+ LOG.debug("#{__FILE__}:#{__LINE__ - 1}: The hash of #{file_path} is #{file_hash}.")
39
40
  # Create a project from the file_path
40
41
  project = Project.new_from_path(file_path)
41
42
  rescue PathNotUnderCodePath
@@ -49,17 +50,31 @@ module WatchTower
49
50
  begin
50
51
  # Create (or fetch) a project
51
52
  project_model = Server::Project.find_or_create_by_name_and_path(project.name, project.path)
53
+ LOG.debug("#{__FILE__}:#{__LINE__ - 1}: Created (or fetched) the project with the id #{project_model.id}")
52
54
 
53
55
  # Create (or fetch) a file
54
56
  file_model = project_model.files.find_or_create_by_path(file_path)
57
+ LOG.debug("#{__FILE__}:#{__LINE__ - 1}: Created (or fetched) the file with the id #{file_model.id}")
55
58
  begin
56
59
  # Create a time entry
57
- file_model.time_entries.create! mtime: File.stat(file_path).mtime,
60
+ time_entry_model = file_model.time_entries.create! mtime: ::File.stat(file_path).mtime,
58
61
  file_hash: file_hash,
59
62
  editor_name: editor.name,
60
63
  editor_version: editor.version
64
+ LOG.debug("#{__FILE__}:#{__LINE__ - 4}: Created a time_entry with the id #{time_entry_model.id}")
61
65
  rescue ActiveRecord::RecordInvalid => e
62
- # This should happen if the mtime is already present
66
+ if e.message =~ /Validation failed: Mtime has already been taken/
67
+ # This should happen if the mtime is already present
68
+ LOG.debug("#{__FILE__}:#{__LINE__ - 8}: The time_entry already exists, nothing were created, error message is #{e.message}")
69
+ elsif e.message =~ /Validation failed: /
70
+ # This should not happen
71
+ LOG.fatal("#{__FILE__}:#{__LINE__ - 11}: The time_entry did not pass validations, #{e.message}.")
72
+ $close_eye = true
73
+ else
74
+ # Some other error happened
75
+ LOG.fatal("#{__FILE__}:#{__LINE__ - 15}: An unknown error has been raised while creating the time_entry, #{e.message}")
76
+ $close_eye = true
77
+ end
63
78
  end
64
79
  rescue ActiveRecord::RecordInvalid => e
65
80
  # This should not happen
@@ -77,6 +92,7 @@ module WatchTower
77
92
  LOG.debug("#{__FILE__}:#{__LINE__}: Closing eye has been requested, end the loop")
78
93
  break
79
94
  else
95
+ # TODO: This should be in the config file, let the user decide how often the loop should start
80
96
  sleep 10
81
97
  end
82
98
  end
@@ -4,7 +4,7 @@ module WatchTower
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
6
  TINY = 1
7
- PRE = 'beta9'
7
+ PRE = 'beta10'
8
8
 
9
9
  def self.version
10
10
  # Init the version
@@ -25,8 +25,7 @@ EOS
25
25
  Open3.stubs(:popen2).with('/usr/bin/gvim --serverlist').yields([mock_pipe(""), mock_pipe(<<-EOC), mock_pipe('')])
26
26
  VIM
27
27
  EOC
28
- Open3.stubs(:popen2).with("/usr/bin/gvim --version").
29
- yields [mock_pipe(""), mock_pipe(<<-EOV), mock_pipe('')]
28
+ version_output = <<-EOV
30
29
  VIM - Vi IMproved 7.3 (2010 Aug 15)
31
30
  Included patches: 1-202, 204-222, 224-322
32
31
  Compiled by 'http://www.opensuse.org/'
@@ -55,12 +54,30 @@ Huge version without GUI. Features included (+) or not (-):
55
54
  Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -I/usr/local/include -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -fno-strict-aliasing -fstack-protector-all
56
55
  Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lm -lnsl -lncurses -lacl -lattr -ldl
57
56
  EOV
57
+
58
+ Open3.stubs(:popen2).with("/usr/bin/vim --version").
59
+ yields [mock_pipe(""), mock_pipe(version_output), mock_pipe('')]
60
+ Open3.stubs(:popen2).with("/usr/bin/gvim --version").
61
+ yields [mock_pipe(""), mock_pipe(version_output), mock_pipe('')]
58
62
  end
59
63
 
60
64
  it { should respond_to :name }
61
65
  its(:name) { should_not raise_error NotImplementedError }
62
66
  its(:name) { should_not be_empty }
63
67
 
68
+ describe "#fetch_version" do
69
+ it { should respond_to :fetch_version }
70
+
71
+ it "should be called on initialize" do
72
+ Vim.any_instance.expects(:fetch_version).once
73
+ Vim.new
74
+ end
75
+
76
+ it "should return 7.3" do
77
+ subject.send(:fetch_version).should == '7.3'
78
+ end
79
+ end
80
+
64
81
  it { should respond_to :version }
65
82
  its(:version) { should_not raise_error NotImplementedError }
66
83
  its(:version) { should_not be_empty }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watch_tower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta9
4
+ version: 0.0.1.beta10
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: 2011-10-26 00:00:00.000000000 Z
12
+ date: 2011-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &6394760 !ruby/object:Gem::Requirement
16
+ requirement: &4456300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *6394760
24
+ version_requirements: *4456300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &6393860 !ruby/object:Gem::Requirement
27
+ requirement: &4469840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.6.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *6393860
35
+ version_requirements: *4469840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activerecord
38
- requirement: &6393200 !ruby/object:Gem::Requirement
38
+ requirement: &4466500 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.1.1
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *6393200
46
+ version_requirements: *4466500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sinatra
49
- requirement: &6392100 !ruby/object:Gem::Requirement
49
+ requirement: &4465200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.3.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *6392100
57
+ version_requirements: *4465200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sinatra-snap
60
- requirement: &6389560 !ruby/object:Gem::Requirement
60
+ requirement: &4464520 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.3.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *6389560
68
+ version_requirements: *4464520
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: haml
71
- requirement: &6413760 !ruby/object:Gem::Requirement
71
+ requirement: &4463680 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 3.1.3
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *6413760
79
+ version_requirements: *4463680
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: grit
82
- requirement: &6411520 !ruby/object:Gem::Requirement
82
+ requirement: &4475980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.4.1
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *6411520
90
+ version_requirements: *4475980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: coffee-script
93
- requirement: &6410160 !ruby/object:Gem::Requirement
93
+ requirement: &4473680 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 2.2.0
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *6410160
101
+ version_requirements: *4473680
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: uglifier
104
- requirement: &6409520 !ruby/object:Gem::Requirement
104
+ requirement: &4485180 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 1.0.3
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *6409520
112
+ version_requirements: *4485180
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sass
115
- requirement: &6408340 !ruby/object:Gem::Requirement
115
+ requirement: &5352920 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 3.1.10
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *6408340
123
+ version_requirements: *5352920
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: sprockets
126
- requirement: &6407700 !ruby/object:Gem::Requirement
126
+ requirement: &5349780 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 2.0.2
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *6407700
134
+ version_requirements: *5349780
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: cronedit
137
- requirement: &6407160 !ruby/object:Gem::Requirement
137
+ requirement: &5347480 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: 0.3.0
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *6407160
145
+ version_requirements: *5347480
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: guard
148
- requirement: &6406660 !ruby/object:Gem::Requirement
148
+ requirement: &5362620 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ~>
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: 0.8.4
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *6406660
156
+ version_requirements: *5362620
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: guard-bundler
159
- requirement: &6406040 !ruby/object:Gem::Requirement
159
+ requirement: &5361640 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ~>
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: 0.1.3
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *6406040
167
+ version_requirements: *5361640
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: guard-rspec
170
- requirement: &6422300 !ruby/object:Gem::Requirement
170
+ requirement: &5360740 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ~>
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: 0.4.5
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *6422300
178
+ version_requirements: *5360740
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: guard-sprockets2
181
- requirement: &6420140 !ruby/object:Gem::Requirement
181
+ requirement: &5359540 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ~>
@@ -186,10 +186,10 @@ dependencies:
186
186
  version: 0.0.5
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *6420140
189
+ version_requirements: *5359540
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: yard
192
- requirement: &6418960 !ruby/object:Gem::Requirement
192
+ requirement: &5358300 !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
195
  - - ~>
@@ -197,10 +197,10 @@ dependencies:
197
197
  version: 0.7.2
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: *6418960
200
+ version_requirements: *5358300
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: rspec
203
- requirement: &6417860 !ruby/object:Gem::Requirement
203
+ requirement: &5356340 !ruby/object:Gem::Requirement
204
204
  none: false
205
205
  requirements:
206
206
  - - ~>
@@ -208,10 +208,10 @@ dependencies:
208
208
  version: 2.6.0
209
209
  type: :development
210
210
  prerelease: false
211
- version_requirements: *6417860
211
+ version_requirements: *5356340
212
212
  - !ruby/object:Gem::Dependency
213
213
  name: rspec-rails
214
- requirement: &6416460 !ruby/object:Gem::Requirement
214
+ requirement: &5368240 !ruby/object:Gem::Requirement
215
215
  none: false
216
216
  requirements:
217
217
  - - ~>
@@ -219,10 +219,10 @@ dependencies:
219
219
  version: 2.6.1
220
220
  type: :development
221
221
  prerelease: false
222
- version_requirements: *6416460
222
+ version_requirements: *5368240
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: capybara
225
- requirement: &6442520 !ruby/object:Gem::Requirement
225
+ requirement: &5365440 !ruby/object:Gem::Requirement
226
226
  none: false
227
227
  requirements:
228
228
  - - ~>
@@ -230,10 +230,10 @@ dependencies:
230
230
  version: 1.1.1
231
231
  type: :development
232
232
  prerelease: false
233
- version_requirements: *6442520
233
+ version_requirements: *5365440
234
234
  - !ruby/object:Gem::Dependency
235
235
  name: launchy
236
- requirement: &6441520 !ruby/object:Gem::Requirement
236
+ requirement: &5394640 !ruby/object:Gem::Requirement
237
237
  none: false
238
238
  requirements:
239
239
  - - ~>
@@ -241,10 +241,10 @@ dependencies:
241
241
  version: 2.0.5
242
242
  type: :development
243
243
  prerelease: false
244
- version_requirements: *6441520
244
+ version_requirements: *5394640
245
245
  - !ruby/object:Gem::Dependency
246
246
  name: mocha
247
- requirement: &6439040 !ruby/object:Gem::Requirement
247
+ requirement: &5402720 !ruby/object:Gem::Requirement
248
248
  none: false
249
249
  requirements:
250
250
  - - ~>
@@ -252,10 +252,10 @@ dependencies:
252
252
  version: 0.10.0
253
253
  type: :development
254
254
  prerelease: false
255
- version_requirements: *6439040
255
+ version_requirements: *5402720
256
256
  - !ruby/object:Gem::Dependency
257
257
  name: factory_girl
258
- requirement: &6437260 !ruby/object:Gem::Requirement
258
+ requirement: &4967600 !ruby/object:Gem::Requirement
259
259
  none: false
260
260
  requirements:
261
261
  - - ~>
@@ -263,10 +263,10 @@ dependencies:
263
263
  version: 2.1.2
264
264
  type: :development
265
265
  prerelease: false
266
- version_requirements: *6437260
266
+ version_requirements: *4967600
267
267
  - !ruby/object:Gem::Dependency
268
268
  name: timecop
269
- requirement: &6435880 !ruby/object:Gem::Requirement
269
+ requirement: &5094520 !ruby/object:Gem::Requirement
270
270
  none: false
271
271
  requirements:
272
272
  - - ~>
@@ -274,10 +274,10 @@ dependencies:
274
274
  version: 0.3.5
275
275
  type: :development
276
276
  prerelease: false
277
- version_requirements: *6435880
277
+ version_requirements: *5094520
278
278
  - !ruby/object:Gem::Dependency
279
279
  name: pry
280
- requirement: &6434980 !ruby/object:Gem::Requirement
280
+ requirement: &5090800 !ruby/object:Gem::Requirement
281
281
  none: false
282
282
  requirements:
283
283
  - - ~>
@@ -285,7 +285,7 @@ dependencies:
285
285
  version: 0.9.6.2
286
286
  type: :development
287
287
  prerelease: false
288
- version_requirements: *6434980
288
+ version_requirements: *5090800
289
289
  description: ! 'Did you ever want to keep track of how much time you _really_ spend
290
290
  on all of
291
291