maxaf-fluke 0.0.1 → 0.0.3
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.
- data/History.txt +14 -0
- data/Manifest.txt +6 -0
- data/Rakefile +1 -0
- data/lib/fluke/cli.rb +9 -3
- data/lib/fluke/monkey_patch.rb +12 -4
- data/lib/fluke/result.rb +9 -1
- data/lib/fluke/watcher.rb +41 -2
- data/lib/fluke.rb +2 -2
- metadata +4 -3
data/History.txt
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
=== 0.0.3 2009-09-08
|
2
|
+
|
3
|
+
* Added Watcher#url_strftime to simplify time-based URL generation.
|
4
|
+
* Even though httpclient aims to be similar to Perl's LWP, it's
|
5
|
+
missing support for file:// URLs. Implemented this locally.
|
6
|
+
|
7
|
+
=== 0.0.2 2009-09-08
|
8
|
+
|
9
|
+
* Added rudimentary result diffing.
|
10
|
+
* Replaced net/http with httpclient.
|
11
|
+
* Figured out synergy between watchers in the DB and their "code"
|
12
|
+
parts stored on the file system.
|
13
|
+
* Implemented generated URLs.
|
14
|
+
|
1
15
|
=== 0.0.1 2009-09-05
|
2
16
|
|
3
17
|
* Initial release: implemented minimum set of core features.
|
data/Manifest.txt
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
bin/fluke
|
2
2
|
db/migrate/0001_create_watchers.rb
|
3
3
|
db/migrate/0002_create_results.rb
|
4
|
+
db/migrate/0003_add_meth_to_watchers.rb
|
5
|
+
db/migrate/0004_add_url_to_results.rb
|
6
|
+
examples/dot-fluke.yml
|
7
|
+
examples/gen_url.rb
|
8
|
+
examples/strftime_url.rb
|
9
|
+
fluke.gemspec
|
4
10
|
History.txt
|
5
11
|
lib/fluke/cli.rb
|
6
12
|
lib/fluke/monkey_patch.rb
|
data/Rakefile
CHANGED
data/lib/fluke/cli.rb
CHANGED
@@ -16,8 +16,9 @@ module Fluke
|
|
16
16
|
|
17
17
|
-OR-
|
18
18
|
|
19
|
-
#{File.basename($0)} [options]
|
20
|
-
#
|
19
|
+
#{File.basename($0)} [options] arg1..argN
|
20
|
+
# args are either files, in which case watcher info is
|
21
|
+
# inferred based on file content, or watcher names
|
21
22
|
Options are:
|
22
23
|
BANNER
|
23
24
|
opts.separator ""
|
@@ -36,7 +37,12 @@ module Fluke
|
|
36
37
|
|
37
38
|
if arguments.size > 0 then
|
38
39
|
arguments.uniq.each do |name|
|
39
|
-
|
40
|
+
if File.exists?(name) and !File.directory?(name) then
|
41
|
+
path = File.expand_path(name)
|
42
|
+
Fluke.class_eval(File.read(path), path)
|
43
|
+
else
|
44
|
+
Fluke.watch name
|
45
|
+
end
|
40
46
|
end
|
41
47
|
else
|
42
48
|
Watcher.find(:all).each do |watcher|
|
data/lib/fluke/monkey_patch.rb
CHANGED
@@ -1,19 +1,27 @@
|
|
1
1
|
module Fluke
|
2
2
|
module Delays
|
3
3
|
def seconds
|
4
|
-
|
4
|
+
self*1000
|
5
5
|
end
|
6
6
|
|
7
7
|
def minutes
|
8
|
-
|
8
|
+
self.seconds*60
|
9
9
|
end
|
10
10
|
|
11
11
|
def hours
|
12
|
-
|
12
|
+
self.minutes*60
|
13
13
|
end
|
14
14
|
|
15
15
|
def days
|
16
|
-
|
16
|
+
self.hours*24
|
17
|
+
end
|
18
|
+
|
19
|
+
def weeks
|
20
|
+
self.days*7
|
21
|
+
end
|
22
|
+
|
23
|
+
def months
|
24
|
+
self.weeks*4
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
data/lib/fluke/result.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'digest/sha1'
|
2
2
|
require 'aws/s3'
|
3
|
+
require 'differ'
|
3
4
|
|
4
5
|
module Fluke
|
5
6
|
class Result < ActiveRecord::Base
|
@@ -24,10 +25,13 @@ module Fluke
|
|
24
25
|
Body.exists? self.body_key
|
25
26
|
end
|
26
27
|
|
27
|
-
def self.from_response(watcher, content)
|
28
|
+
def self.from_response(watcher, content, generated_url = nil)
|
28
29
|
checksum = Digest::SHA1.hexdigest(content)
|
29
30
|
result = Result.new :checksum => checksum
|
30
31
|
result.watcher = watcher
|
32
|
+
if generated_url and generated_url != watcher.url
|
33
|
+
result.url = generated_url
|
34
|
+
end
|
31
35
|
result.save
|
32
36
|
|
33
37
|
Thread.new do
|
@@ -41,5 +45,9 @@ module Fluke
|
|
41
45
|
|
42
46
|
result
|
43
47
|
end
|
48
|
+
|
49
|
+
def diff_against(right)
|
50
|
+
differ = Differ.diff_by_line(self.body.value, right.body.value)
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|
data/lib/fluke/watcher.rb
CHANGED
@@ -9,14 +9,48 @@ module Fluke
|
|
9
9
|
attr_accessor :thread
|
10
10
|
|
11
11
|
def run
|
12
|
+
generated_url = self.generate_url
|
13
|
+
Fluke::log { "#{self}: generated URL: #{generated_url}" }
|
14
|
+
|
15
|
+
if generated_url =~ /^file\:\/\/(.+)$/
|
16
|
+
run_file File.expand_path($1)
|
17
|
+
else
|
18
|
+
run_http generated_url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def run_file(path)
|
23
|
+
result = Result.from_response(self, File.read(path), "file://#{path}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_http(generated_url)
|
12
27
|
hc = HTTPClient.new
|
13
28
|
http_method = self.meth.downcase.to_sym
|
14
29
|
unless hc.respond_to?(http_method)
|
15
30
|
Fluke::log { "#{self}: invalid method '#{http_method}', converting to :get" }
|
16
31
|
http_method = :get
|
17
32
|
end
|
18
|
-
res = hc.send(http_method,
|
19
|
-
result = Result.from_response(self, res.body.dump.dup)
|
33
|
+
res = hc.send(http_method, generated_url, { 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache' })
|
34
|
+
result = Result.from_response(self, res.body.dump.dup, generated_url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def url_generator(&block)
|
38
|
+
@generate_url = true
|
39
|
+
@url_generator = block
|
40
|
+
end
|
41
|
+
|
42
|
+
def url_strftime(offset = 0)
|
43
|
+
self.url_generator do |raw|
|
44
|
+
(Time.now + offset/1000.000).strftime(raw)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_url
|
49
|
+
if @generate_url
|
50
|
+
return @url_generator.call(self.url)
|
51
|
+
else
|
52
|
+
return self.url
|
53
|
+
end
|
20
54
|
end
|
21
55
|
|
22
56
|
def wait
|
@@ -26,5 +60,10 @@ module Fluke
|
|
26
60
|
def to_s
|
27
61
|
"Watcher<#{name}>"
|
28
62
|
end
|
63
|
+
|
64
|
+
def last_result(checksum = nil)
|
65
|
+
cond = [ "checksum = ?", checksum ] if checksum
|
66
|
+
results.find(:first, :conditions => cond, :order => "created_at desc")
|
67
|
+
end
|
29
68
|
end
|
30
69
|
end
|
data/lib/fluke.rb
CHANGED
@@ -9,7 +9,7 @@ require 'activerecord'
|
|
9
9
|
require 'aws/s3'
|
10
10
|
|
11
11
|
module Fluke
|
12
|
-
VERSION = '0.0.
|
12
|
+
VERSION = '0.0.3'
|
13
13
|
ROOT = Dir.new(File.expand_path(File.dirname(__FILE__) + "/../"))
|
14
14
|
DEFAULT_CONF_PATH = "~/.fluke.yml"
|
15
15
|
@@verbose = false
|
@@ -61,7 +61,7 @@ module Fluke
|
|
61
61
|
ActiveRecord::Base.logger = Logger.new(@@log_here) if verbose?
|
62
62
|
ActiveRecord::Base.establish_connection(@@conf[:db])
|
63
63
|
AWS::S3::Base.establish_connection!(@@conf[:s3][:auth])
|
64
|
-
Result::Body.set_current_bucket_to @@conf[:s3][:bucket]
|
64
|
+
Result::Body.set_current_bucket_to @@conf[:s3][:bucket][:result]
|
65
65
|
rescue => e
|
66
66
|
STDERR.puts e.inspect
|
67
67
|
return false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maxaf-fluke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Afonov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-08 00:00:00 -07:00
|
13
13
|
default_executable: fluke
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- test/test_helper.rb
|
95
95
|
has_rdoc: false
|
96
96
|
homepage: http://github.com/maxaf/fluke
|
97
|
+
licenses:
|
97
98
|
post_install_message:
|
98
99
|
rdoc_options:
|
99
100
|
- --main
|
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
requirements: []
|
116
117
|
|
117
118
|
rubyforge_project: fluke
|
118
|
-
rubygems_version: 1.
|
119
|
+
rubygems_version: 1.3.5
|
119
120
|
signing_key:
|
120
121
|
specification_version: 3
|
121
122
|
summary: A simple resource observer designed to detect change over time.
|