Skip to content

Instantly share code, notes, and snippets.

@DougHall
Created October 26, 2011 18:21
Show Gist options
  • Save DougHall/1317246 to your computer and use it in GitHub Desktop.
Save DougHall/1317246 to your computer and use it in GitHub Desktop.
ics guardfile
# 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
@rymai
Copy link

rymai commented Oct 26, 2011

You should pass paths to concatenate L.50 and L.54 and change concatenate signature to def concatenate(paths) L.11.

Also, L.61 you can remove the block, modified paths will be passed to run_on_change and then passed to concatenate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment