Class: AutoCron
- Inherits:
-
Object
- Object
- AutoCron
- Defined in:
- lib/auto_cron.rb
Instance Method Summary collapse
-
#initialize(templates, application) ⇒ AutoCron
constructor
A new instance of AutoCron.
- #updated_crontab ⇒ Object
Constructor Details
#initialize(templates, application) ⇒ AutoCron
Returns a new instance of AutoCron.
4 5 6 7 8 9 |
# File 'lib/auto_cron.rb', line 4 def initialize( templates, application ) require 'erb' @auto_cron_dir = ENV["CONFIG_AUTO_CRON"] @templates = templates.split(",") @application = application end |
Instance Method Details
#updated_crontab ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/auto_cron.rb', line 11 def updated_crontab # Check for unopened or unclosed identifier blocks if read_crontab.index(comment_open) && !read_crontab.index(comment_close) warn "[fail] Unclosed indentifier; Your crontab file contains '#{comment_open}', but no '#{comment_close}'" exit(1) elsif !read_crontab.index(comment_open) && read_crontab.index(comment_close) warn "[fail] Unopened indentifier; Your crontab file contains '#{comment_close}', but no '#{comment_open}'" exit(1) end # If an existing identier block is found, replace it with the new cron entries if read_crontab.index(comment_open) && read_crontab.index(comment_close) read_crontab.gsub(Regexp.new("#{comment_open}.+#{comment_close}", Regexp::MULTILINE), auto_cron_wrapped.chomp) else # Otherwise, append the new cron entries after any existing ones [read_crontab, auto_cron_wrapped].join("\n\n") end end |