Skip to content
Browse files

reformat

  • Loading branch information...
1 parent e76deb5 commit 808ed5725c24a399d4ba62df7b1918bb9647786f @ttilley committed Jan 26, 2011
Showing with 93 additions and 92 deletions.
  1. +1 −1 Rakefile
  2. +3 −3 example.rb
  3. +13 −13 fssm.gemspec
  4. +2 −1 lib/fssm.rb
  5. +2 −2 lib/fssm/support.rb
  6. +3 −3 profile/prof-cache.rb
  7. +3 −3 profile/prof-pathname-rubinius.rb
  8. +7 −7 profile/prof-pathname.rb
  9. +10 −10 spec/count_down_latch.rb
  10. +34 −34 spec/monitor_spec.rb
  11. +15 −15 spec/path_spec.rb
View
2 Rakefile
@@ -5,7 +5,7 @@ require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
- spec.spec_opts = ['--format', 'specdoc']
+ spec.spec_opts = ['--format', 'specdoc']
end
task :default => :spec
View
6 example.rb
@@ -6,7 +6,7 @@
require 'fssm'
FSSM.monitor('.', '**/*') do
- update {|b, r| puts "Update in #{b} to #{r}"}
- delete {|b, r| puts "Delete in #{b} to #{r}"}
- create {|b, r| puts "Create in #{b} to #{r}"}
+ update { |b, r| puts "Update in #{b} to #{r}" }
+ delete { |b, r| puts "Delete in #{b} to #{r}" }
+ create { |b, r| puts "Create in #{b} to #{r}" }
end
View
26 fssm.gemspec
@@ -3,22 +3,22 @@ $:.push File.expand_path("../lib", __FILE__)
require "fssm/version"
Gem::Specification.new do |s|
- s.name = "fssm"
- s.version = FSSM::VERSION
- s.platform = Gem::Platform::RUBY
- s.authors = ["Travis Tilley", "Nathan Weizenbaum", "Chris Eppstein",
- "Jonathan Castello", "Tuomas Kareinen"]
- s.email = ["ttilley@gmail.com"]
- s.homepage = "https://github.com/ttilley/fssm"
- s.summary = %q{File System State Monitor}
- s.description = %q{The File System State Monitor keeps track of the state of any number of paths and will fire events when said state changes (create/update/delete). FSSM supports using FSEvents on MacOS, Inotify on GNU/Linux, and polling anywhere else.}
+ s.name = "fssm"
+ s.version = FSSM::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Travis Tilley", "Nathan Weizenbaum", "Chris Eppstein",
+ "Jonathan Castello", "Tuomas Kareinen"]
+ s.email = ["ttilley@gmail.com"]
+ s.homepage = "https://github.com/ttilley/fssm"
+ s.summary = %q{File System State Monitor}
+ s.description = %q{The File System State Monitor keeps track of the state of any number of paths and will fire events when said state changes (create/update/delete). FSSM supports using FSEvents on MacOS, Inotify on GNU/Linux, and polling anywhere else.}
s.rubyforge_project = "fssm"
- s.files = `git ls-files`.split("\n")
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = ["lib"]
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
+ s.require_paths = ["lib"]
s.add_development_dependency "rspec", "1.3.0"
end
View
3 lib/fssm.rb
@@ -1,14 +1,15 @@
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
+#noinspection ALL
module FSSM
FileNotFoundError = Class.new(StandardError)
FileNotRealError = Class.new(StandardError)
CallbackError = Class.new(StandardError)
class << self
def dbg(msg=nil)
- STDERR.puts(msg)
+ STDERR.puts("FSSM -> #{msg}")
end
def monitor(*args, &block)
View
4 lib/fssm/support.rb
@@ -21,8 +21,8 @@ def usable_backend
when linux?
'rb-inotify'
end
- STDERR.puts("FSSM: An optimized backend is available for this platform!")
- STDERR.puts(" gem install #{optimal}")
+ FSSM.dbg("An optimized backend is available for this platform!")
+ FSSM.dbg(" gem install #{optimal}")
end
choice
View
6 profile/prof-cache.rb
@@ -5,7 +5,7 @@
require 'rubygems'
require 'ruby-prof'
-$test_path = FSSM::Pathname.new('..').expand_path
+$test_path = FSSM::Pathname.new('..').expand_path
$test_files = FSSM::Pathname.glob(File.join($test_path, '**', '*'))
RubyProf.start
@@ -33,8 +33,8 @@
print "\n\n"
end
-result = RubyProf.stop
-output = File.new('prof.html', 'w+')
+result = RubyProf.stop
+output = File.new('prof.html', 'w+')
printer = RubyProf::GraphHtmlPrinter.new(result)
printer.print(output, :min_percent => 1)
View
6 profile/prof-pathname-rubinius.rb
@@ -2,7 +2,7 @@
require 'pathname'
-$test_path = "#{Pathname.new('..').expand_path}"
+$test_path = "#{Pathname.new('..').expand_path}"
$iterations = 900000
if ARGV.first == 'native'
@@ -20,7 +20,7 @@ def segments
end
$iterations.times do |num|
- p = ::Pathname.new($test_path)
+ p = ::Pathname.new($test_path)
segments = p.segments
end
else
@@ -29,7 +29,7 @@ def segments
require 'fssm'
$iterations.times do |num|
- p = FSSM::Pathname.new($test_path)
+ p = FSSM::Pathname.new($test_path)
segments = p.segments
end
end
View
14 profile/prof-pathname.rb
@@ -6,7 +6,7 @@
require 'rubygems'
require 'ruby-prof'
-$test_path = "#{Pathname.new('..').expand_path}"
+$test_path = "#{Pathname.new('..').expand_path}"
$iterations = 90000
class Pathname
@@ -32,15 +32,15 @@ def segments
puts "FSSM::Pathname iteration #{iteration}"
RubyProf.resume
- p = FSSM::Pathname.new($test_path)
+ p = FSSM::Pathname.new($test_path)
segments = p.segments
RubyProf.pause
end
puts "\nFSSM Pathname profile finished\n\n"
-result = RubyProf.stop
-output = File.new('prof-fssm-pathname.html', 'w+')
+result = RubyProf.stop
+output = File.new('prof-fssm-pathname.html', 'w+')
printer = RubyProf::GraphHtmlPrinter.new(result)
printer.print(output, :min_percent => 1)
@@ -54,15 +54,15 @@ def segments
puts "::Pathname iteration #{iteration}"
RubyProf.resume
- p = ::Pathname.new($test_path)
+ p = ::Pathname.new($test_path)
segments = p.segments
RubyProf.pause
end
puts "\nruby Pathname profile finished\n\n"
-result = RubyProf.stop
-output = File.new('prof-plain-pathname.html', 'w+')
+result = RubyProf.stop
+output = File.new('prof-plain-pathname.html', 'w+')
printer = RubyProf::GraphHtmlPrinter.new(result)
printer.print(output, :min_percent => 1)
View
20 spec/count_down_latch.rb
@@ -9,7 +9,7 @@ class CountDownLatch
def initialize(to)
@count = to.to_i
raise ArgumentError, "cannot count down from negative integer" unless @count >= 0
- @lock = Mutex.new
+ @lock = Mutex.new
@condition = ConditionVariable.new
end
@@ -37,7 +37,7 @@ def test_requires_positive_count
def test_basic_latch_usage
latch = CountDownLatch.new(1)
- name = "foo"
+ name = "foo"
Thread.new do
name = "bar"
latch.count_down
@@ -49,7 +49,7 @@ def test_basic_latch_usage
def test_basic_latch_usage_inverted
latch = CountDownLatch.new(1)
- name = "foo"
+ name = "foo"
Thread.new do
latch.wait
assert_equal(0, latch.count)
@@ -67,7 +67,7 @@ def test_count_down_from_zero_skips_wait
def test_count_down_twice_with_thread
latch = CountDownLatch.new(2)
- name = "foo"
+ name = "foo"
Thread.new do
latch.count_down
name = "bar"
@@ -80,7 +80,7 @@ def test_count_down_twice_with_thread
def test_count_down_twice_with_two_parallel_threads
latch = CountDownLatch.new(2)
- name = "foo"
+ name = "foo"
Thread.new { latch.count_down }
Thread.new do
name = "bar"
@@ -93,7 +93,7 @@ def test_count_down_twice_with_two_parallel_threads
def test_count_down_twice_with_two_chained_threads
latch = CountDownLatch.new(2)
- name = "foo"
+ name = "foo"
Thread.new do
latch.count_down
Thread.new do
@@ -108,8 +108,8 @@ def test_count_down_twice_with_two_chained_threads
def test_count_down_with_multiple_waiters
proceed_latch = CountDownLatch.new(2)
- check_latch = CountDownLatch.new(2)
- results = {}
+ check_latch = CountDownLatch.new(2)
+ results = {}
Thread.new do
proceed_latch.wait
results[:first] = 1
@@ -131,9 +131,9 @@ def test_count_down_with_multiple_waiters
def test_interleaved_latches
change_1_latch = CountDownLatch.new(1)
- check_latch = CountDownLatch.new(1)
+ check_latch = CountDownLatch.new(1)
change_2_latch = CountDownLatch.new(1)
- name = "foo"
+ name = "foo"
Thread.new do
name = "bar"
change_1_latch.count_down
View
68 spec/monitor_spec.rb
@@ -25,9 +25,9 @@ def create_handler(type, latch)
end
def run_monitor(num_events_to_expect=0, options={})
- event_latch = CountDownLatch.new(num_events_to_expect)
- @handler_results = Hash.new {|hash, key| hash[key] = []}
- thread = Thread.new do
+ event_latch = CountDownLatch.new(num_events_to_expect)
+ @handler_results = Hash.new { |hash, key| hash[key] = [] }
+ thread = Thread.new do
monitor = FSSM::Monitor.new(options)
monitor.path(@tmp_dir) do |p|
p.create(&create_handler(:create, event_latch))
@@ -36,7 +36,7 @@ def run_monitor(num_events_to_expect=0, options={})
end
monitor.run
end
- sleep 1 # give time for monitor to start up
+ sleep 1 # give time for monitor to start up
yield if block_given?
event_latch.wait
thread.kill
@@ -126,74 +126,74 @@ def run_monitor(num_events_to_expect=0, options={})
run_monitor(3, :directories => true) do
FileUtils.mv @tmp_dir + "/root/yawn", @tmp_dir + "/root/old_yawn"
end
- @handler_results[:create].should include([@tmp_dir, 'root/old_yawn', :directory])
- @handler_results[:delete].should include([@tmp_dir, 'root/yawn', :directory])
- @handler_results[:update].should include([@tmp_dir, 'root', :directory])
+ @handler_results[:create].should include([@tmp_dir, 'root/old_yawn', :directory])
+ @handler_results[:delete].should include([@tmp_dir, 'root/yawn', :directory])
+ @handler_results[:update].should include([@tmp_dir, 'root', :directory])
end
it "should call create, update, and delete callbacks upon directory moving to another directory" do
run_monitor(3, :directories => true) do
FileUtils.mv @tmp_dir + "/root/yawn", @tmp_dir + "/old_yawn"
end
- @handler_results[:create].should include([@tmp_dir, 'old_yawn', :directory])
- @handler_results[:delete].should include([@tmp_dir, 'root/yawn', :directory])
- @handler_results[:update].should include([@tmp_dir, 'root', :directory])
+ @handler_results[:create].should include([@tmp_dir, 'old_yawn', :directory])
+ @handler_results[:delete].should include([@tmp_dir, 'root/yawn', :directory])
+ @handler_results[:update].should include([@tmp_dir, 'root', :directory])
end
it "should call create, update, and delete callbacks upon file renaming in the same directory" do
run_monitor(3, :directories => true) do
FileUtils.mv @tmp_dir + "/root/file.rb", @tmp_dir + "/root/old_file.rb"
end
@handler_results[:create].should include([@tmp_dir, 'root/old_file.rb', :file])
- @handler_results[:delete].should include([@tmp_dir, 'root/file.rb', :file])
- @handler_results[:update].should include([@tmp_dir, 'root', :directory])
+ @handler_results[:delete].should include([@tmp_dir, 'root/file.rb', :file])
+ @handler_results[:update].should include([@tmp_dir, 'root', :directory])
end
it "should call create, update, and delete callbacks upon file moving to another directory" do
run_monitor(3, :directories => true) do
FileUtils.mv @tmp_dir + "/root/file.rb", @tmp_dir + "/old_file.rb"
end
- @handler_results[:create].should include([@tmp_dir, 'old_file.rb', :file])
+ @handler_results[:create].should include([@tmp_dir, 'old_file.rb', :file])
@handler_results[:delete].should include([@tmp_dir, 'root/file.rb', :file])
- @handler_results[:update].should include([@tmp_dir, 'root', :directory])
+ @handler_results[:update].should include([@tmp_dir, 'root', :directory])
end
it "should call delete callbacks upon directory structure deletion, in reverse order" do
expected_delete_events = [
- ['root/yawn', :directory],
- ['root/moo/cow.txt', :file],
- ['root/moo', :directory],
- ['root/file.yml', :file],
- ['root/file.rb', :file],
- ['root/file.css', :file],
- ['root/duck/quack.txt', :file],
- ['root/duck', :directory],
- ['root', :directory]
+ ['root/yawn', :directory],
+ ['root/moo/cow.txt', :file],
+ ['root/moo', :directory],
+ ['root/file.yml', :file],
+ ['root/file.rb', :file],
+ ['root/file.css', :file],
+ ['root/duck/quack.txt', :file],
+ ['root/duck', :directory],
+ ['root', :directory]
]
run_monitor(expected_delete_events.size, :directories => true) do
FileUtils.rm_rf @tmp_dir + '/.'
end
@handler_results[:create].should == []
- @handler_results[:delete].should == expected_delete_events.map {|(file, type)| [@tmp_dir, file, type]}
+ @handler_results[:delete].should == expected_delete_events.map { |(file, type)| [@tmp_dir, file, type] }
@handler_results[:update].should == []
end
it "should call create callbacks upon directory structure creation, in order" do
expected_create_events = [
- ['new_root', :directory],
- ['new_root/duck', :directory],
- ['new_root/duck/quack.txt', :file],
- ['new_root/file.css', :file],
- ['new_root/file.rb', :file],
- ['new_root/file.yml', :file],
- ['new_root/moo', :directory],
- ['new_root/moo/cow.txt', :file],
- ['new_root/yawn', :directory]
+ ['new_root', :directory],
+ ['new_root/duck', :directory],
+ ['new_root/duck/quack.txt', :file],
+ ['new_root/file.css', :file],
+ ['new_root/file.rb', :file],
+ ['new_root/file.yml', :file],
+ ['new_root/moo', :directory],
+ ['new_root/moo/cow.txt', :file],
+ ['new_root/yawn', :directory]
]
run_monitor(expected_create_events.size, :directories => true) do
FileUtils.cp_r @tmp_dir + '/root/.', @tmp_dir + '/new_root'
end
- @handler_results[:create].should == expected_create_events.map {|(file, type)| [@tmp_dir, file, type]}
+ @handler_results[:create].should == expected_create_events.map { |(file, type)| [@tmp_dir, file, type] }
@handler_results[:delete].should == []
@handler_results[:update].should == []
end
View
30 spec/path_spec.rb
@@ -3,11 +3,11 @@
describe "The File System State Monitor" do
describe "paths" do
it "should accept a valid filesystem directory" do
- lambda {FSSM::Path.new("#{@watch_root}")}.should_not raise_error
+ lambda { FSSM::Path.new("#{@watch_root}") }.should_not raise_error
end
it "should not accept an invalid filesystem directory" do
- lambda {FSSM::Path.new('/does/not/exist/kthxbye')}.should raise_error
+ lambda { FSSM::Path.new('/does/not/exist/kthxbye') }.should raise_error
end
it "should default the path to the current directory" do
@@ -28,7 +28,7 @@
end
it "should accept an optional option parameter" do
- lambda {FSSM::Path.new('.', '**/*.yml', :foo => :bar)}.should_not raise_error
+ lambda { FSSM::Path.new('.', '**/*.yml', :foo => :bar) }.should_not raise_error
end
it "should default the glob to ['**/*']" do
@@ -37,32 +37,32 @@
end
it "should accept a callback for update events" do
- path = FSSM::Path.new
- callback = lambda {|base, relative| return true}
+ path = FSSM::Path.new
+ callback = lambda { |base, relative| return true }
path.update(&callback)
(path.update).should == callback
end
it "should accept a callback for delete events" do
- path = FSSM::Path.new
- callback = lambda {|base, relative| return true}
+ path = FSSM::Path.new
+ callback = lambda { |base, relative| return true }
path.delete(&callback)
(path.delete).should == callback
end
it "should accept a callback for create events" do
- path = FSSM::Path.new
- callback = lambda {|base, relative| return true}
+ path = FSSM::Path.new
+ callback = lambda { |base, relative| return true }
path.create(&callback)
(path.create).should == callback
end
it "should accept a configuration block" do
path = FSSM::Path.new "#{@watch_root}" do
glob '**/*.yml'
- update {|base, relative| 'success'}
- delete {|base, relative| 'success'}
- create {|base, relative| 'success'}
+ update { |base, relative| 'success' }
+ delete { |base, relative| 'success' }
+ create { |base, relative| 'success' }
end
"#{path}".should == "#{@watch_root}"
@@ -78,9 +78,9 @@
it "should pass file type to callbacks as the third argument if :directories option is used" do
path = FSSM::Path.new "#{@watch_root}", nil, :directories => true do
glob '**/*.yml'
- update {|base, relative, type| [base, relative, type]}
- delete {|base, relative, type| [base, relative, type]}
- create {|base, relative, type| [base, relative, type]}
+ update { |base, relative, type| [base, relative, type] }
+ delete { |base, relative, type| [base, relative, type] }
+ create { |base, relative, type| [base, relative, type] }
end
"#{path}".should == "#{@watch_root}"

0 comments on commit 808ed57

Please sign in to comment.
Something went wrong with that request. Please try again.