Skip to content

Instantly share code, notes, and snippets.

@lenada
Created April 17, 2013 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenada/5400986 to your computer and use it in GitHub Desktop.
Save lenada/5400986 to your computer and use it in GitHub Desktop.
Guardfile for php-tricorder `guard -G ThisGuardfile`
# A hackish inline Guardfile for php-tricorder
# More info at https://github.com/guard/guard#readme
# https://github.com/chartjes/php-tricorder/#readme
# watching certain files in a directory, the tricorder 'fires' on change
# running php-tricorder continously is probably not that useful
# still using this file as a Guardfile `guard -G ThisGuardfile`
# is a shortcut to easily run tricorder and get hints for testing approaches instantly
# you may have to change the locations of phpdoc and tricorder executable below.
require 'guard/guard'
module ::Guard
class Phptricorder < Guard
def run_on_change(paths)
phpdocresult = `#{phpdoc_command(paths)}`
#results = "#{ phpdocresult }".split(/\r?\n/)
#puts results
run_tricorder(tricorder_command(paths))
end
private
def phpdoc_command(paths)
cmd_parts = []
cmd_parts << phpdoc_executable
cmd_parts << 'parse --filename'
cmd_parts << paths[0]
cmd_parts << ' -t'
cmd_parts.join(' ')
end
def tricorder_command(paths)
cmd_parts = []
cmd_parts << 'php ' + tricorder_executable
cmd_parts << '--path=' + File.dirname(paths[0])
cmd_parts << './output/structure.xml'
cmd_parts.join(' ')
end
def run_tricorder(command)
puts command
result = `#{command}`
puts result
if $?.to_i == 1
puts "An Error occured"
#::Guard::Notifier.notify(results[1], :title => 'Notification title' + line, :image => :failed)
end
end
def tricorder_executable
options.fetch(:executable){'~/Stuff/php-tricorder/tricorder.php'}
end
def phpdoc_executable
options.fetch(:phpdoc){'/usr/local/php5/bin/phpdoc'}
end
end
end
notification :terminal_notifier
guard 'phptricorder' do
# watch all changes in .php files inside the module folder
# defining more specific watch patterns would get better results
watch(%r{module/.+\.php}) { |m| "#{m[0]}"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment