snooper 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 634956e753d4252eb400d1e90476e5dba0dfb71b
4
- data.tar.gz: 48822ec94381e1dde8c9a576aaf3467b1c4192fd
3
+ metadata.gz: ffb4bc98d8fad3cc57acac6069b1ca64e9f31bf3
4
+ data.tar.gz: 7d4d1302798e019dc6b0920bf5908faaa45d4ee8
5
5
  SHA512:
6
- metadata.gz: 6ffcae7b1adb30d9d1a0e3d85ded93dc9b0e67afd7234e1fa52df6c61df60dcc0a80066598aadc3f47e8e81d734fd2342b2f559cc751ef7d071eca2a2ac9e74e
7
- data.tar.gz: 294184c9327a8084d66001631931c54db89ce1211ad2d53847e93b3a31fd1315751c184d3a6735a4750c58f287a386e383368be8dae65923db1573010a4ef6b1
6
+ metadata.gz: bd29330b32b1ce8d0bedde0fbe04e493143c61870dfc709187de1c9d1f747eb026e713e0103b0654ba989db16f456661f4df19f385c83b843cab36ad283b26d1
7
+ data.tar.gz: 7688ca83d1038ea2e04e567d03a388e8e4bf59e4a0170990ba78da600a11972516d7975fdb363571d28a6d3ca567d514205a0964259a1edacb36ee6d3ba59076
data/bin/snooper CHANGED
@@ -10,10 +10,13 @@ require 'optparse'
10
10
  require 'yaml'
11
11
 
12
12
  ##
13
- # Main program loop
13
+ # Internal: Main program loop
14
+ #
15
+ # options - the hash containing the options.
14
16
  #
15
17
  # Do our stuff, and exit cleanly when interrupted.
16
-
18
+ #
19
+ # Returns nothing.
17
20
  def test_loop(options)
18
21
  begin
19
22
  dirs = options[:paths].empty? ? './' : options[:paths]
@@ -25,9 +28,9 @@ def test_loop(options)
25
28
  end
26
29
 
27
30
  ##
28
- # Parse the command line and load the options
31
+ # Internal: Parse the command line and load the options
29
32
  #
30
-
33
+ # Returns a processed options hash
31
34
  def get_options
32
35
 
33
36
  helptext = <<END
data/lib/snooper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  ##
2
+ # Public: This module provides the snooping abilities.
3
+ #
2
4
  # This program runs in the background watching for file changes. When a file
3
5
  # change is dtected a command is run. It is intended to watch repos for changes
4
6
  # and run unit tests automatically when source files are changed.
@@ -6,8 +8,7 @@
6
8
  # Author:: Will Speak (@willspeak)
7
9
  # Copyright:: Copyright (c) 2013 Will Speak
8
10
  # License:: Snoop is open source! See LICENCE.md for more details.
9
-
10
- # This module provides the snooping abilities.
11
+ #
11
12
  #
12
13
  # For most applications calling the +Snooper#watch+ method should be sufficient
13
14
  # if Snooper::Snoop objects can be created directly.
@@ -17,9 +18,12 @@ module Snooper
17
18
  require 'snooper/version'
18
19
 
19
20
  ##
20
- # Watch for changes in a directory
21
+ # Public: Watch for changes in a directory
22
+ #
23
+ # args - The Hash containing the options. See Snooper::Snoop.new for more
24
+ # information
21
25
  #
22
- # @param args - see Snooper::Snoop.new for more information
26
+ # Returns the reseult of the run.
23
27
  def self.watch(*args)
24
28
  george = Snoop.new *args
25
29
  george.run
data/lib/snooper/hook.rb CHANGED
@@ -6,13 +6,13 @@
6
6
  module Snooper
7
7
 
8
8
  ##
9
- # File Change Hook
9
+ # Public: File Change Hook
10
10
  #
11
11
  # Hooks represent a command that is fired when a given file changes.
12
12
  class Hook
13
13
 
14
14
  ##
15
- # Public : Create a new Hook
15
+ # Public: Create a new Hook
16
16
  #
17
17
  # pattern - The String or Regex to match
18
18
  # command - The String containig the command to be run
@@ -26,7 +26,7 @@ module Snooper
26
26
  end
27
27
 
28
28
  ##
29
- # Public : Fire the hook
29
+ # Public: Fire the hook
30
30
  #
31
31
  # Returns the exit code of the command
32
32
  def fire
@@ -34,7 +34,7 @@ module Snooper
34
34
  end
35
35
 
36
36
  ##
37
- # Public : Run the Hook
37
+ # Public: Run the Hook
38
38
  #
39
39
  # path - The String to match agains the hook
40
40
  #
@@ -48,7 +48,7 @@ module Snooper
48
48
  end
49
49
 
50
50
  ##
51
- # Private : Convert a string, regex, or regex-linke to Regexp
51
+ # Internal: Convert a string, regex, or regex-linke to Regexp
52
52
  #
53
53
  # regex - The String or Regexp to convert
54
54
  #
data/lib/snooper/snoop.rb CHANGED
@@ -8,7 +8,7 @@ require 'snooper/hook'
8
8
  module Snooper
9
9
 
10
10
  ##
11
- # Watches over a directory, executing a comand when files change
11
+ # Public: Watches over a directory, executing a comand when files change
12
12
  #
13
13
  # The fine-grained behaviour of this class is controlled by the parameters
14
14
  # passed to the +new+ method.
@@ -19,14 +19,16 @@ module Snooper
19
19
  require 'terminfo'
20
20
 
21
21
  ##
22
- # Create a new source code spy
22
+ # Public: Create a new source code spy
23
23
  #
24
- # @param [String, Array] path - the path (or paths) to begin watching
25
- # @param [Hash] args - the options hash
26
- # [+:filters+] [Array,String,Regexp] Files to include, empty for all
27
- # [+:ignored+] [Array,String,Regexp] Paths to ignore
28
- # [+:command+] [String] The command to run when changes are detected
29
-
24
+ # path - the String or Array path (or paths) to begin watching
25
+ # args - the Hash of options
26
+ # :filters - The Array, String or Regexp files to include, empty or
27
+ # to signify no filter.
28
+ # :ignored - The Array, String or Regexp paths to ignore. As above.
29
+ # :command - The String containing the command to run when changes
30
+ # are detected
31
+ # :hooks - The Array of hashes to be converted into Hook objects
30
32
  def initialize(path, args = {})
31
33
  to_regex = Proc.new { |r| Regexp.try_convert(r) || Regexp.new(r) }
32
34
 
@@ -40,12 +42,12 @@ module Snooper
40
42
  end
41
43
 
42
44
  ##
43
- # Public : Create Hook Objects
45
+ # Public: Create Hook Objects
44
46
  #
45
47
  # raw_hooks - The Array of maps. Each map should contain the pattern to
46
48
  # match and the command to run.
47
49
  #
48
- # Returns an Array of Hook
50
+ # Returns an Array of Hooks
49
51
  def create_hooks(raw_hooks)
50
52
  raw_hooks.to_a.map do |hook|
51
53
  Hook.new hook["pattern"], hook["command"]
@@ -53,11 +55,14 @@ module Snooper
53
55
  end
54
56
 
55
57
  ##
56
- # Time Command
58
+ # Internal: Time Command
57
59
  #
58
60
  # Run a command and time how long it takes. The exit status of the command
59
61
  # and the time taken to run the command are both returned.
60
-
62
+ #
63
+ # command - The command to run
64
+ #
65
+ # Returns the result of the command and the time taken to run it, in seconds
61
66
  def time_command(command)
62
67
  before = Time.new
63
68
  result = system command
@@ -66,11 +71,18 @@ module Snooper
66
71
  end
67
72
 
68
73
  ##
69
- # Change callback
74
+ # Internal: Change callback
70
75
  #
71
76
  # Called when a filesystem change is detected by +listen+. Runs the command
72
77
  # passed to t he constructor and prints a summary of the output.
73
-
78
+ #
79
+ # modified - The Array of paths that were modified since the last change
80
+ # added - The Array of paths that were added since the last change
81
+ # removed - The Array of paths that were removed since the last change
82
+ #
83
+ # Raises nothing.
84
+ #
85
+ # Returns nothing.
74
86
  def on_change(modified, added, removed)
75
87
  begin
76
88
  # Puase the listener to avoid spurious triggers from build output
@@ -105,14 +117,17 @@ module Snooper
105
117
  end
106
118
 
107
119
  ##
108
- # Prettify a status line
120
+ # Internal: Prettify a status line
109
121
  #
110
122
  # Prints the message at the center of the line, automatically detected
111
123
  # from the terminal info. If a block is supplied then the resulting message
112
124
  # is post-filtered by it before being returned.
113
125
  #
114
- # @param message - the message to print
115
-
126
+ # message - the message to print
127
+ #
128
+ # Yields the String that has been aligned to the terminal width.
129
+ #
130
+ # Returns the prettified String.
116
131
  def statusbar(message, time=nil)
117
132
  message << " (#{time.round(3)}s)" if time
118
133
  message = message.to_s.center TermInfo.screen_width - 1
@@ -120,12 +135,13 @@ module Snooper
120
135
  end
121
136
 
122
137
  ##
123
- # Main run loop
138
+ # Public: Main run loop
124
139
  #
125
140
  # Registers for filesystem notifications and dispatches them to the
126
- # +on_change+ handler. This method also forces a dummy update to ensure that
141
+ # #on_change handler. This method also forces a dummy update to ensure that
127
142
  # tests are run when watching begins.
128
-
143
+ #
144
+ # Returns the result of the listener
129
145
  def run
130
146
 
131
147
  # Force a change to start with
@@ -137,7 +153,7 @@ module Snooper
137
153
  :ignore => @ignored)
138
154
  @listener.change &callback_helper
139
155
 
140
- @listener.start
156
+ @listener.start!
141
157
  end
142
158
  end
143
159
  end
@@ -1,10 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Author:: Will Speak (@willspeak)
3
+ # Copyright:: Copyright (c) 2013 Will Speak
4
+ # License:: Snoop is open source! See LICENCE.md for more details.
5
+
1
6
  module Snooper
2
7
 
3
8
  ##
4
- # The library version for this module
9
+ # Public: The library version for this module
5
10
  #
6
11
  # This should conform to SemVer. If this is changed it should be the only
7
12
  # thing that changes in the comit.
8
-
9
- VERSION = '1.0.0'
13
+ VERSION = '1.0.1'
10
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snooper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Speak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-06 00:00:00.000000000 Z
11
+ date: 2013-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '0.7'
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '0.7'
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-terminfo
43
43
  requirement: !ruby/object:Gem::Requirement