snooper 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf6a2f05350d836af71cda01ebc7a8eec69550dc
4
- data.tar.gz: 9750a737010032c0c16550ee5126fe2dd3ca98cf
3
+ metadata.gz: 35bd66062da4d8e2f2ee037335468a1364209c70
4
+ data.tar.gz: eb1bd60ec064498b8d94341c8c1782a2594c91ab
5
5
  SHA512:
6
- metadata.gz: 1cae260fd97fed5f5066e0a8c6633fd2a625ba8c3de148cb1dc06b0eb12791ddb25bb3b025b52fc297b18bc89c62afa09bda171b5a9ca0c82b8b0894d7bf75e6
7
- data.tar.gz: 6a74486dc5d7ae30ad1284c7daff857dae120c86cdbaac3cfb85b522e025312a43913124b001611275fc99560e1b7f53370ce3a871e55e4ac8eb0c33288b88d7
6
+ metadata.gz: 074f9ad4672586cf8674ec2cf7080664a41ab19c572e4045994f2e96e8fd6d8f33686d76b481864d404321370bab03b77e6142c808d92c303b58c446ff213384
7
+ data.tar.gz: c5c2b33e21c15744bdd670f5b6505c44136bdce46cc636bf5f818f7434573d7012726a38db67bf07d7c4f860c298b0638d708fd053b7a8b7b28eddfeacca4bfd
@@ -32,13 +32,16 @@ module Snooper
32
32
  # hooks - The Array of Hook objects
33
33
  attr_accessor :hooks
34
34
 
35
+ # file_path - The location the config was loaded from
36
+ attr_accessor :file_path
37
+
35
38
  ##
36
39
  # Public: create a new config object
37
40
  #
38
41
  # base_path - The String representing the path from which all the other
39
42
  # paths should be resolved. Nil to use the current directory.
40
43
  # command - The command to execute when a change satisfies all the
41
- # predicates.
44
+ # predicates.
42
45
  # options - The hash containing all of the optinal parameters.
43
46
  # :paths - The Array of the paths to watch, relative to the
44
47
  # base. Nil or empty to watch the whole directory.
@@ -105,6 +108,23 @@ module Snooper
105
108
  instance
106
109
  end
107
110
 
111
+ ##
112
+ # Public : Re-Load the config from a YAML file
113
+ #
114
+ # Retuns true if the config was successully reloaded, false if loading
115
+ # failed for any reason, and nil if the config wasn't loaded from a file in
116
+ # in the first place
117
+ def reload
118
+ if @file_path
119
+ initialize_from_yaml @file_path
120
+ true
121
+ else
122
+ nil
123
+ end
124
+ rescue
125
+ false
126
+ end
127
+
108
128
  ##
109
129
  # Implementaiton: load and initialise a config from a YAML file
110
130
  #
@@ -133,6 +153,8 @@ module Snooper
133
153
 
134
154
  opts[key.to_sym] = value
135
155
  end
156
+
157
+ @file_path = (file_path.is_a?(String) && file_path) || file_path.path
136
158
 
137
159
  initialize base_path, command, options
138
160
  end
@@ -4,6 +4,7 @@
4
4
  # License:: Snooper is open source! See LICENCE.md for more details.
5
5
 
6
6
  module Snooper
7
+ require 'snooper/version'
7
8
 
8
9
  module Options
9
10
  require 'optparse'
@@ -45,7 +46,7 @@ END
45
46
  end
46
47
 
47
48
  parser.on("--version", "show version information") do
48
- puts "Snooper v#{Snooper::VERSION}"
49
+ puts "Snooper v#{VERSION}"
49
50
  exit
50
51
  end
51
52
 
data/lib/snooper/snoop.rb CHANGED
@@ -144,6 +144,29 @@ module Snooper
144
144
  #
145
145
  # Returns the result of the listener
146
146
  def run
147
+ if @config.file_path
148
+ dir = File.dirname @config.file_path
149
+ Listen.to dir, filter: %r{^#{@config.file_path}$} do |*args|
150
+ @listener.stop if @listener
151
+ end
152
+ end
153
+
154
+ # loop forever listening, each time the above block causes the listener
155
+ # to stop it will re-start listening with the new config.
156
+ while true
157
+ do_listening
158
+ @config.reload
159
+ end
160
+ end
161
+
162
+ ##
163
+ # Internal : Do the Filesystem Listening
164
+ #
165
+ # This function blocks while it listens to the filsystem for changes. When
166
+ # the lisetner terminates it returns the listener's status
167
+ #
168
+ # Returns the result of the listener
169
+ def do_listening
147
170
  in_dir @config.base_path do
148
171
  # Force a change to start with
149
172
  run_command
@@ -157,5 +180,6 @@ module Snooper
157
180
  @listener.start!
158
181
  end
159
182
  end
183
+
160
184
  end
161
185
  end
@@ -10,5 +10,5 @@ module Snooper
10
10
  #
11
11
  # This should conform to SemVer. If this is changed it should be the only
12
12
  # thing that changes in the comit.
13
- VERSION = '2.0.0'
13
+ VERSION = '2.1.0'
14
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: 2.0.0
4
+ version: 2.1.0
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-20 00:00:00.000000000 Z
11
+ date: 2013-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored