Skip to content

Instantly share code, notes, and snippets.

@DougHall
Created October 27, 2011 22:38
Show Gist options
  • Save DougHall/1321107 to your computer and use it in GitHub Desktop.
Save DougHall/1321107 to your computer and use it in GitHub Desktop.
guard guardfile for monitoring changes and deletions of *.ics files
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require "/Users/dhall/work/scripts/ruby/calendars/cal_concatenator"
require 'logger'
require 'guard/guard'
module ::Guard
class CalGuard < ::Guard::Guard
def concatenate(paths)
logs_dir = "/Users/dhall/work/scripts/ruby/calendars/logs"
destination_dir = "/Users/dhall/work/scripts/ruby/calendars/results"
log = Logger.new("#{logs_dir}/ics_mod.log", 'monthly')
log.level = Logger::INFO
catter = CalConcatenator.new
paths.grep(/^.+\.ics$/).each do |modfile|
puts modfile # print the filename when received.
apple_guid = CalConcatenator.apple_guid(modfile)
unless apple_guid
log.error "An apple-generateduid could not be found within '#{filename}'."
return(exit)
end
common_name = CalConcatenator.get_common_name(apple_guid)
unless common_name
log.error "The common name could not be determined for apple-generateduid: '#{apple_guid}'."
return(exit)
end
last_slash_pos = modfile.rindex('/')
parent_dirname = modfile[0,last_slash_pos]
unless File.directory? parent_dirname
log.error "Folder: '#{parent_dirname}' was not found."
return(exit)
end
outfilepath = File.join(destination_dir, "#{common_name}.ics")
catter.concatenate_calendars(parent_dirname, outfilepath)
if File.exists?(outfilepath)
log.info("The #{common_name} calendar was modified.")
else
log.info("The #{common_name} calendar was deleted.")
end
end
end
def run_on_change(paths)
concatenate(paths)
end
def run_on_deletion(paths)
concatenate(paths)
end
end
end
ignore_paths 'wi'
guard 'calguard'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment