auto_cron 0.1.2 → 0.1.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/VERSION +1 -1
- data/auto_cron.gemspec +2 -1
- data/lib/auto_cron.rb +54 -50
- data/lib/auto_cron/railtie.rb +9 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/auto_cron.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{auto_cron}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alex Farrill"]
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"generators/auto_cron/templates/publish.erb",
|
31
31
|
"install.rb",
|
32
32
|
"lib/auto_cron.rb",
|
33
|
+
"lib/auto_cron/railtie.rb",
|
33
34
|
"lib/capistrano/auto_cron.rb",
|
34
35
|
"lib/tasks/auto_cron_tasks.rake",
|
35
36
|
"test/helper.rb",
|
data/lib/auto_cron.rb
CHANGED
@@ -1,65 +1,69 @@
|
|
1
|
-
|
2
|
-
def initialize( template, application )
|
3
|
-
require 'erb'
|
1
|
+
require 'auto_cron/railtie' if defined?(Rails)
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
warn "[fail] Unclosed indentifier; Your crontab file contains '#{comment_open}', but no '#{comment_close}'"
|
14
|
-
exit(1)
|
15
|
-
elsif !read_crontab.index(comment_open) && read_crontab.index(comment_close)
|
16
|
-
warn "[fail] Unopened indentifier; Your crontab file contains '#{comment_close}', but no '#{comment_open}'"
|
17
|
-
exit(1)
|
3
|
+
module AutoCron
|
4
|
+
class AutoCron
|
5
|
+
def initialize( template, application )
|
6
|
+
require 'erb'
|
7
|
+
|
8
|
+
@auto_cron_dir = File.join( Rails.root, "config", "auto_cron" )
|
9
|
+
@template = template
|
10
|
+
@application = application
|
18
11
|
end
|
12
|
+
|
13
|
+
def updated_crontab
|
14
|
+
# Check for unopened or unclosed identifier blocks
|
15
|
+
if read_crontab.index(comment_open) && !read_crontab.index(comment_close)
|
16
|
+
warn "[fail] Unclosed indentifier; Your crontab file contains '#{comment_open}', but no '#{comment_close}'"
|
17
|
+
exit(1)
|
18
|
+
elsif !read_crontab.index(comment_open) && read_crontab.index(comment_close)
|
19
|
+
warn "[fail] Unopened indentifier; Your crontab file contains '#{comment_close}', but no '#{comment_open}'"
|
20
|
+
exit(1)
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
# If an existing identier block is found, replace it with the new cron entries
|
24
|
+
if read_crontab.index(comment_open) && read_crontab.index(comment_close)
|
25
|
+
read_crontab.gsub(Regexp.new("#{comment_open}.+#{comment_close}", Regexp::MULTILINE), auto_cron_wrapped.chomp)
|
26
|
+
else # Otherwise, append the new cron entries after any existing ones
|
27
|
+
[read_crontab, auto_cron_wrapped].join("\n\n")
|
28
|
+
end
|
25
29
|
end
|
26
|
-
end
|
27
30
|
|
28
|
-
protected
|
31
|
+
protected
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
def auto_cron_wrapped
|
34
|
+
@auto_cron_wrapped ||= [comment_open, auto_cron_inner, comment_close].join("\n") + "\n"
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
def auto_cron_inner
|
38
|
+
header_template = File.join( @auto_cron_dir, 'header.erb' )
|
39
|
+
header = if File.exist?( header_template )
|
40
|
+
ERB.new( File.read( header_template ) ).result
|
41
|
+
else
|
42
|
+
''
|
43
|
+
end
|
44
|
+
full_template_path = File.join( @auto_cron_dir, "#{ @template }.erb" )
|
45
|
+
header + "\n\n" + ERB.new( File.read( full_template_path ) ).result
|
40
46
|
end
|
41
|
-
full_template_path = File.join( @auto_cron_dir, "#{ @template }.erb" )
|
42
|
-
header + "\n\n" + ERB.new( File.read( full_template_path ) ).result
|
43
|
-
end
|
44
47
|
|
45
|
-
|
46
|
-
|
48
|
+
def read_crontab
|
49
|
+
return @current_crontab if @current_crontab
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
command = ['crontab -l']
|
52
|
+
command_results = %x[#{command.join(' ')} 2> /dev/null]
|
53
|
+
@current_crontab = $?.exitstatus.zero? ? command_results : ''
|
54
|
+
end
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
def comment_base
|
57
|
+
"auto_cron generated tasks for: #{ @application }"
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
def comment_open
|
61
|
+
"# Begin #{ comment_base }"
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
def comment_close
|
65
|
+
"# End #{ comment_base }"
|
66
|
+
end
|
64
67
|
|
68
|
+
end
|
65
69
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_cron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Farrill
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- generators/auto_cron/templates/publish.erb
|
88
88
|
- install.rb
|
89
89
|
- lib/auto_cron.rb
|
90
|
+
- lib/auto_cron/railtie.rb
|
90
91
|
- lib/capistrano/auto_cron.rb
|
91
92
|
- lib/tasks/auto_cron_tasks.rake
|
92
93
|
- test/helper.rb
|