everyx 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/everyx.rb +45 -8
- metadata +2 -2
data/History.txt
CHANGED
data/lib/everyx.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Everyx
|
2
|
-
VERSION = '1.0.
|
2
|
+
VERSION = '1.0.2'
|
3
|
+
|
4
|
+
# The class that responsible for running the periodic task
|
3
5
|
class Everyx
|
4
6
|
def initialize
|
5
7
|
@threads = []
|
@@ -32,6 +34,46 @@ module Everyx
|
|
32
34
|
|
33
35
|
|
34
36
|
module PeriodicTasks
|
37
|
+
# This class will monitor a file, and create an NServer message when
|
38
|
+
# every the file modification time changes.
|
39
|
+
#
|
40
|
+
# You'll have to set the +fname+ for the file.
|
41
|
+
class FileMonitor
|
42
|
+
require 'rubygems'
|
43
|
+
require 'nserver'
|
44
|
+
|
45
|
+
attr :fname, :writable => true
|
46
|
+
|
47
|
+
def initialize
|
48
|
+
@fname = nil
|
49
|
+
@mtime = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def check
|
53
|
+
new_time = File.mtime(@fname)
|
54
|
+
if new_time != @mtime
|
55
|
+
@mtime = new_time
|
56
|
+
return true
|
57
|
+
else
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def call
|
63
|
+
if check
|
64
|
+
NServer::Client.try_notify("File #{@fname} modified.")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# This class will fetch and parse a RSS feed. It will create an NServer
|
71
|
+
# alert with all the 'titles' of the entries whenever the feed updates.
|
72
|
+
#
|
73
|
+
# Try not to run this one every minute, as it generally annoys the feed
|
74
|
+
# owner. 15 minutes is fairly "standard."
|
75
|
+
#
|
76
|
+
# You'll have to set the +uri+ before you schedule this.
|
35
77
|
class RSSNotifier
|
36
78
|
require 'rss/1.0'
|
37
79
|
require 'rss/2.0'
|
@@ -40,10 +82,8 @@ module Everyx
|
|
40
82
|
require 'nserver'
|
41
83
|
|
42
84
|
attr :uri, :writable => true
|
43
|
-
attr :delay, :writable => true
|
44
|
-
|
45
85
|
def initialize
|
46
|
-
@uri
|
86
|
+
@uri = nil
|
47
87
|
@last = nil
|
48
88
|
end
|
49
89
|
|
@@ -54,7 +94,7 @@ module Everyx
|
|
54
94
|
rss.items.each do |item|
|
55
95
|
if item.link != @last
|
56
96
|
first_new = item.link unless first_new
|
57
|
-
new << item.title
|
97
|
+
new << "* #{item.title}"
|
58
98
|
else
|
59
99
|
break
|
60
100
|
end
|
@@ -63,10 +103,7 @@ module Everyx
|
|
63
103
|
@last = first_new if first_new
|
64
104
|
|
65
105
|
if new.size > 0
|
66
|
-
puts "#{new.size} items"
|
67
106
|
NServer::Client.try_notify( new.join("\n") )
|
68
|
-
else
|
69
|
-
puts "No new items."
|
70
107
|
end
|
71
108
|
end
|
72
109
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.5
|
|
3
3
|
specification_version: 2
|
4
4
|
name: everyx
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2007-11-
|
6
|
+
version: 1.0.2
|
7
|
+
date: 2007-11-13 00:00:00 -05:00
|
8
8
|
summary: Code to run some classes every x seconds
|
9
9
|
require_paths:
|
10
10
|
- lib
|