forked from guard/guard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4d3744f
Showing
28 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pkg/* | ||
*.gem | ||
.bundle | ||
|
||
## MAC OS | ||
.DS_Store | ||
.Trashes | ||
.com.apple.timemachine.supported | ||
.fseventsd | ||
Desktop DB | ||
Desktop DF |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "http://rubygems.org" | ||
|
||
gemspec |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
guard (0.1.0.beta.1) | ||
growl (~> 1.0.3) | ||
libnotify (~> 0.1.3) | ||
rb-inotify | ||
sys-uname (~> 0.8.4) | ||
thor (~> 0.14.2) | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
diff-lcs (1.1.2) | ||
ffi (0.6.3) | ||
rake (>= 0.8.7) | ||
growl (1.0.3) | ||
libnotify (0.1.4) | ||
ffi (>= 0.6.2) | ||
rake (0.8.7) | ||
rb-inotify (0.8.1) | ||
ffi (>= 0.5.0) | ||
rspec (2.0.0.beta.19) | ||
rspec-core (= 2.0.0.beta.19) | ||
rspec-expectations (= 2.0.0.beta.19) | ||
rspec-mocks (= 2.0.0.beta.19) | ||
rspec-core (2.0.0.beta.19) | ||
rspec-expectations (2.0.0.beta.19) | ||
diff-lcs (>= 1.1.2) | ||
rspec-mocks (2.0.0.beta.19) | ||
sys-uname (0.8.4) | ||
thor (0.14.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (~> 1.0.1) | ||
growl (~> 1.0.3) | ||
guard! | ||
libnotify (~> 0.1.3) | ||
rb-inotify | ||
rspec (~> 2.0.0.beta.22) | ||
sys-uname (~> 0.8.4) | ||
thor (~> 0.14.2) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# guard 'spork', :rspec_port => 9010 do | ||
# watch('^config/initializers/.*') | ||
# end | ||
|
||
def super | ||
`say yo` | ||
end | ||
|
||
guard 'rspec', :version => 2 do | ||
watch('^spec/(.*)_spec.rb') | ||
watch('^lib/(.*).rb') { |m| "spec/#{m[1]}_spec.rb" } | ||
watch('^spec/spec_helper.rb') { "spec" } | ||
# watch('^spec/spec_helper.rb') { `say hello` } | ||
# watch('^spec/(.*)_spec\.rb') | ||
# watch('^app/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" } | ||
# watch('^app/(.*)\.html.erb') { |m| "spec/#{m[1]}_spec.rb" } | ||
# watch('^lib/(.*)\.rb') { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
# watch('^spec/spec_helper\.rb') { |m| "spec" } | ||
# watch('^config/routes\.rb') { |m| "spec/routing" } | ||
# watch('^spec/factories\.rb') { |m| "spec/model" } | ||
# watch('^app/controllers/application_controller\.rb') { |m| "spec/controllers" } | ||
end | ||
|
||
# guard 'livereload' do | ||
# end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2010 Thibaud Guillaume-Gentil | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= Guard | ||
|
||
Documentation is coming. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks | ||
|
||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new(:spec) | ||
task :default => :spec |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'guard' | ||
require 'guard/cli' | ||
|
||
Guard::CLI.start |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env ruby | ||
require 'rubygems' | ||
require 'rb-inotify' | ||
|
||
folders = Array.new | ||
notifier = INotify::Notifier.new | ||
|
||
notifier.watch(ARGV.first || '.', :modify, :recursive) do |event| | ||
dir = File.expand_path(File.dirname(event.absolute_name)) + '/' | ||
if !folders.include?(dir) | ||
folders << dir | ||
end | ||
end | ||
|
||
while true do | ||
notifier.process | ||
|
||
if !folders.empty? | ||
$stdout.puts folders.join(' ') | ||
$stdout.flush | ||
folders.clear | ||
end | ||
|
||
sleep(0.1) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Workaround to make Rubygems believe it builds a native gem | ||
require 'mkmf' | ||
create_makefile('none') | ||
|
||
if `uname -s`.chomp == 'Darwin' | ||
gem_root = File.expand_path(File.join('..')) | ||
darwin_verion = `uname -r`.to_i | ||
sdk_verion = { 9 => '10.5', 10 => '10.6', 11 => '10.7' }[darwin_verion] | ||
|
||
raise "Darwin #{darwin_verion} is not supported" unless sdk_verion | ||
|
||
# Compile the actual fsevent_watch binary | ||
system("CFLAGS='-isysroot /Developer/SDKs/MacOSX#{sdk_verion}.sdk -mmacosx-version-min=#{sdk_verion}' /usr/bin/gcc -framework CoreServices -o '#{gem_root}/bin/fsevent_watch' fsevent/fsevent_watch.c") | ||
|
||
unless File.executable?("#{gem_root}/bin/fsevent_watch") | ||
raise "Compilation of fsevent_watch failed (see README)" | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <CoreServices/CoreServices.h> | ||
|
||
void callback(ConstFSEventStreamRef streamRef, | ||
void *clientCallBackInfo, | ||
size_t numEvents, | ||
void *eventPaths, | ||
const FSEventStreamEventFlags eventFlags[], | ||
const FSEventStreamEventId eventIds[] | ||
) { | ||
// Print modified dirs | ||
int i; | ||
char **paths = eventPaths; | ||
for (i = 0; i < numEvents; i++) { | ||
printf("%s", paths[i]); | ||
printf(" "); | ||
} | ||
printf("\n"); | ||
fflush(stdout); | ||
} | ||
|
||
int main (int argc, const char * argv[]) { | ||
// Create event stream | ||
CFStringRef pathToWatch = CFStringCreateWithCString(kCFAllocatorDefault, argv[1], kCFStringEncodingUTF8); | ||
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&pathToWatch, 1, NULL); | ||
void *callbackInfo = NULL; | ||
FSEventStreamRef stream; | ||
CFAbsoluteTime latency = 0.1; | ||
stream = FSEventStreamCreate( | ||
kCFAllocatorDefault, | ||
callback, | ||
callbackInfo, | ||
pathsToWatch, | ||
kFSEventStreamEventIdSinceNow, | ||
latency, | ||
kFSEventStreamCreateFlagNone | ||
); | ||
|
||
// Add stream to run loop | ||
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | ||
FSEventStreamStart(stream); | ||
CFRunLoopRun(); | ||
|
||
return 2; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path('../lib', __FILE__) | ||
require 'guard/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'guard' | ||
s.version = Guard::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ['Thibaud Guillaume-Gentil'] | ||
s.email = ['[email protected]'] | ||
s.homepage = 'http://rubygems.org/gems/guard' | ||
s.summary = 'Guard keep an eye on your files event' | ||
s.description = 'Guard is a command line tool to easly manage script launch when your files change' | ||
|
||
s.rubyforge_project = 'guard' | ||
|
||
s.add_development_dependency 'bundler', '~> 1.0.1' | ||
s.add_development_dependency 'rspec', '~> 2.0.0.beta.22' | ||
|
||
s.add_dependency 'thor', '~> 0.14.2' | ||
s.add_dependency 'sys-uname', '~> 0.8.4' | ||
# Mac OS X | ||
s.add_dependency 'growl', '~> 1.0.3' | ||
# Linux | ||
s.add_dependency 'rb-inotify' | ||
s.add_dependency 'libnotify', '~> 0.1.3' | ||
|
||
s.files = Dir.glob('{bin,images,lib,ext}/**/*') + %w[LICENSE README.rdoc] | ||
s.extensions = ['ext/extconf.rb'] | ||
s.executable = 'guard' | ||
s.require_path = 'lib' | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Guard | ||
|
||
autoload :UI, 'guard/ui' | ||
autoload :Dsl, 'guard/dsl' | ||
autoload :Interactor, 'guard/interactor' | ||
autoload :Listener, 'guard/listener' | ||
autoload :Watcher, 'guard/watcher' | ||
autoload :Notifier, 'guard/notifier' | ||
|
||
class << self | ||
attr_accessor :options, :guards, :listener | ||
|
||
def start(options = {}) | ||
@options = options | ||
@listener = Listener.new | ||
@guards = [] | ||
|
||
Dsl.evaluate_guardfile | ||
Interactor.init_signal_traps | ||
|
||
listener.on_change do |files| | ||
run do | ||
guards.each do |guard| | ||
paths = Watcher.match_files(guard, files) | ||
guard.run_on_change(paths) unless paths.empty? | ||
end | ||
end | ||
end | ||
|
||
UI.info "Guard is now watching at '#{Dir.pwd}'" | ||
guards.each(&:start) | ||
listener.start | ||
end | ||
|
||
def add_guard(name, watchers = [], options = {}) | ||
require "guard/#{name.downcase}" | ||
guard_class = ObjectSpace.each_object(Class).detect { |c| c.to_s.downcase.match "^guard::#{name.downcase}" } | ||
@guards << guard_class.new(watchers, options) | ||
end | ||
|
||
def run | ||
listener.stop | ||
yield | ||
listener.start | ||
end | ||
|
||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'thor' | ||
require 'guard/version' | ||
|
||
module Guard | ||
class CLI < Thor | ||
default_task :start | ||
|
||
desc "start", "Starts guard" | ||
method_option :clear, :type => :boolean, :default => false, :aliases => '-c', :banner => "Auto clear shell after each change" | ||
def start | ||
Guard.start(options) | ||
end | ||
|
||
desc "version", "Prints the guard's version information" | ||
def version | ||
Guard::UI.info "Guard version #{Guard::VERSION}" | ||
end | ||
map %w(-v --version) => :version | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Guard | ||
class Dsl | ||
|
||
def self.evaluate_guardfile | ||
guardfile = "#{Dir.pwd}/Guardfile" | ||
dsl = new | ||
dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1) | ||
rescue | ||
UI.error "Guardfile not found or invalid" | ||
exit 1 | ||
end | ||
|
||
def guard(name, options = {}, &definition) | ||
@watchers = [] | ||
definition.call | ||
Guard.add_guard(name, @watchers, options) | ||
end | ||
|
||
def watch(pattern, &action) | ||
@watchers << Guard::Watcher.new(pattern, action) | ||
end | ||
|
||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Guard | ||
class Guard | ||
attr_accessor :watchers, :options | ||
|
||
def initialize(watchers = [], options = {}) | ||
@watchers, @options = watchers, options | ||
end | ||
|
||
# ================ | ||
# = Guard method = | ||
# ================ | ||
|
||
def start | ||
true | ||
end | ||
|
||
def stop | ||
true | ||
end | ||
|
||
def reload | ||
true | ||
end | ||
|
||
def run_all | ||
true | ||
end | ||
|
||
def run_on_change(paths) | ||
true | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.