Created
October 26, 2011 18:21
-
-
Save DougHall/1317246 to your computer and use it in GitHub Desktop.
ics guardfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A sample Guardfile | |
# More info at https://github.com/guard/guard#readme | |
require "~/work/scripts/ruby/calendars/cal_concatenator" | |
require 'logger' | |
require 'guard/guard' | |
module ::Guard | |
class CalGuard < ::Guard::Guard | |
def concatenate | |
# How to get "paths"? | |
this_dir = File.expand_path(File.dirname(modfile)) | |
logs_dir = "#{this_dir}/logs" | |
results_dir = "#{this_dir}/results" | |
[logs_dir,results_dir].each do |this_dir| | |
Dir.mkdir(this_dir) unless File.directory?(this_dir) | |
end | |
log = Logger.new("#{logs_dir}/ics_mod.log", 'monthly') | |
log.level = Logger::INFO | |
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 | |
catter = CalConcatenator.new | |
outfilepath = File.join(results_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 | |
def run_on_change(paths) | |
concatenate | |
end | |
def run_on_deletion(paths) | |
concatenate | |
end | |
end | |
end | |
guard 'cal_guard' do | |
ignore_paths 'wi' | |
watch(%r{^(.+\.ics)$}) { |m| "self.concatenate(m[1])"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should pass
paths
toconcatenate
L.50 and L.54 and changeconcatenate
signature todef concatenate(paths)
L.11.Also, L.61 you can remove the block, modified paths will be passed to
run_on_change
and then passed toconcatenate
.