Skip to content

Commit

Permalink
Merge branch '3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred committed Dec 3, 2013
2 parents 56d7bc8 + 97ffac4 commit 0005684
Show file tree
Hide file tree
Showing 53 changed files with 940 additions and 1,079 deletions.
17 changes: 8 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
.*.sw?
*.gem
.rbenv-version
/.rbenv-version
.DS_Store
coverage
rdoc
pkg
html/*.html
html/*.rid
html/*.css
html/classes
html/files
/coverage
/rdoc
/pkg
/html
/Gemfile.lock
/tmp/
/.idea
6 changes: 4 additions & 2 deletions .kick
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
recipe :ignore
recipe :ruby

Kicker::Recipes::Ruby.runner_bin = 'bacon'

process do |files|
test_files = files.take_and_map do |file|
case file
when %r{^lib/kicker(\.rb|/validate\.rb|/growl\.rb)$}
["test/initialization_test.rb", ("test/filesystem_change_test.rb" if $1 == '.rb')]
["spec/initialization_spec.rb", ("spec/filesystem_change_spec.rb" if $1 == '.rb')]
when %r{^lib/kicker/(.+)\.rb$}
"test/#{$1}_test.rb"
"spec/#{$1}_spec.rb"
end
end

Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
rvm:
- 2.0.0
- 1.9.3
- 1.9.2
- 1.8.7

script: "rake"
script: "rake"
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
source "http://rubygems.org"
source "https://rubygems.org"
gemspec

gem 'rake'

platforms :mri_18 do
gem 'rdoc'
end
45 changes: 0 additions & 45 deletions Gemfile.lock

This file was deleted.

26 changes: 15 additions & 11 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@

A lean, agnostic, flexible file-change watcher.

https://github.com/alloy/kicker/raw/master/html/images/kikker.jpg

Meet king kikker, kicking stuff in your computers is his dream come true!

<i>Drawing by Manfred Stienstra. The character is purely fictional, so if you
feel offended; live with it.</i>

== Installation

$ gem install kicker -s http://gemcutter.org

== The short version

Usage: ./bin/kicker [options] [paths to watch]

Available recipes: ignore, jstest, rails, ruby.

-s, --silent Keep output to a minimum.
-q, --quiet Quiet output. Don't print timestamps when logging.
-c, --clear Clear console before each run.
Expand Down Expand Up @@ -64,7 +57,8 @@ A few recipes come shipped with Kicker:
HeadlessSquirrel[http://github.com/Fingertips/Headless-squirrel].
* Ignore, ignores logs, tmp, and svn and git files.

Add your own shared recipes to <tt>~/.kick</tt>.
Add your own shared recipes to <tt>~/.kick</tt> folder or
current working directory <tt>.kick</tt>.

=== Project specific handlers

Expand Down Expand Up @@ -110,7 +104,7 @@ be added:
test_files = files.take_and_map do |file|
if path =~ %r{^app/views/mailer/\w+\.erb$}
'test/unit/mailer_test.rb'

# elsif ... handle more app specific stuff
end
end
Expand Down Expand Up @@ -138,6 +132,16 @@ To load recipes from your <tt>~/.kick</tt> file:
That’s basically it, just remember that the order of specifying handlers _can_
be important in your decision on where to specify handlers.

== Notifiers

For platform specific notifications we use the notify gem. For supported
backends see: https://github.com/jugyo/notify#feature.

You select the notify backend by setting the NOTIFY environment variable.

gem install terminal-notifier
env NOTIFY=terminal-notifier kicker

== Contributors

* Manfred Stienstra (@manfred)
Expand Down
22 changes: 11 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
begin
require 'rdoc/task'
rescue LoadError
require 'rake/rdoctask'
end
require 'rdoc/task'

desc "Run tests"
task :test do
desc "Run specs"
task :spec do
# shuffle to ensure that tests are run in different order
files = FileList['test/**/*_test.rb'].map { |f| f[0,f.size-3] }.shuffle
sh "ruby -Ilib -I. -r '#{files.join("' -r '")}' -e ''"
files = FileList['spec/**/*_spec.rb'].shuffle
sh "bundle exec bacon #{files.map { |file| "'#{file}'" }.join(' ')}"
end

namespace :docs do
Rake::RDocTask.new('generate') do |t|
RDoc::Task.new('generate') do |t|
t.main = "README.rdoc"
t.rdoc_files.include("README.rdoc", "lib/**/*.rb")
t.options << '--charset=utf8'
end
end

task :default => :test
task :docs => 'docs:generate' do
FileUtils.cp_r('images', 'html')
end

task :default => :spec
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

File renamed without changes
24 changes: 15 additions & 9 deletions kicker.gemspec
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
# -*- encoding: utf-8 -*-

$:.unshift File.expand_path('../lib', __FILE__)
require 'kicker/version'
require 'date'

Gem::Specification.new do |s|
s.name = "kicker"
s.version = Kicker::VERSION
s.date = Date.today
s.date = Time.new
s.license = 'MIT'

s.summary = "A lean, agnostic, flexible file-change watcher."
s.description = "Allows you to fire specific command on file-system change."
s.authors = ["Eloy Duran", "Manfred Stienstra"]
s.homepage = "http://github.com/alloy/kicker"
s.email = %w{ [email protected] [email protected] }

s.executables = %w{ kicker }
s.require_paths = %w{ lib vendor }
s.files = Dir['bin/kicker', '{lib,vendor}/**/*.rb', 'README.rdoc', 'LICENSE', 'html/images/kikker.jpg']
s.files = Dir['bin/kicker',
'lib/**/*.rb',
'README.rdoc',
'LICENSE',
'html/images/kikker.jpg']
s.extra_rdoc_files = %w{ LICENSE README.rdoc }

s.add_runtime_dependency("listen", '~> 1.1.0')

s.add_development_dependency("rake")
s.add_development_dependency("rdoc") # purely so it doesn't warn about deprecated rake task
s.add_runtime_dependency("listen", '~> 1.3.0')
s.add_runtime_dependency("notify", '~> 0.5.2')

s.add_development_dependency("mocha")
s.add_development_dependency("test-unit")
s.add_development_dependency("test-spec")
s.add_development_dependency("bacon")
s.add_development_dependency("mocha-on-bacon")
s.add_development_dependency("activesupport")
s.add_development_dependency("fakefs")
end

55 changes: 26 additions & 29 deletions lib/kicker.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
$:.unshift File.expand_path('../../vendor', __FILE__)

require 'kicker/version'
require 'kicker/fsevents'
require 'kicker/callback_chain'
require 'kicker/core_ext'
require 'kicker/growl'
require 'kicker/job'
require 'kicker/notification'
require 'kicker/options'
require 'kicker/utils'
require 'kicker/recipes'

class Kicker #:nodoc:
def self.run(argv = ARGV)
Kicker::Options.parse(argv)
new.start
new.start.loop!
end

attr_reader :last_event_processed_at

def initialize
finished_processing!
end

def paths
@paths ||= Kicker.paths.map { |path| File.expand_path(path) }
end

def start
validate_options!

log "Watching for changes on: #{paths.join(', ')}"
log ''

Kicker::Growl.start! if Kicker::Growl.usable? && Kicker::Growl.use?

run_startup_chain
run_watch_dog!

self
end

def loop!
(Thread.list - [Thread.current, Thread.main]).each(&:join)
end

private

def validate_options!
validate_paths_and_command!
validate_paths_exist!
end

def validate_paths_and_command!
if startup_chain.empty? && process_chain.empty? && pre_process_chain.empty?
puts Kicker::Options.parser.help
exit
end
end

def validate_paths_exist!
paths.each do |path|
unless File.exist?(path)
Expand All @@ -58,60 +62,53 @@ def validate_paths_exist!
end
end
end

def run_watch_dog!
dirs = @paths.map { |path| File.directory?(path) ? path : File.dirname(path) }
watch_dog = Kicker::FSEvents.start_watching(dirs, :latency => self.class.latency) do |events|
process events
end

trap('INT') do
log "Exiting ..."
watch_dog.stop
exit
end

wait_for_threads
end

def wait_for_threads
(Thread.list - [Thread.current]).each(&:join)
end

def run_startup_chain
startup_chain.call([], false)
end

def finished_processing!
@last_event_processed_at = Time.now
end

def process(events)
unless (files = changed_files(events)).empty?
Utils.should_clear_screen = true
full_chain.call(files)
finished_processing!
end
end

def changed_files(events)
make_paths_relative(events.map do |event|
files_in_directory(event.path).select { |file| file_changed_since_last_event? file }
end.flatten.uniq.sort)
end

def files_in_directory(dir)
Dir.entries(dir).sort[2..-1].map { |f| File.join(dir, f) }
rescue Errno::ENOENT
[]
end

def file_changed_since_last_event?(file)
File.mtime(file) > @last_event_processed_at
rescue Errno::ENOENT
false
end

def make_paths_relative(files)
return files if files.empty?
wd = Dir.pwd
Expand Down
Loading

0 comments on commit 0005684

Please sign in to comment.