Skip to content

Commit

Permalink
Update source docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mynyml committed Oct 2, 2009
1 parent c32f129 commit 85bf997
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 0 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

* update source docs

* 1.9 compatibility

* sometimes an action is fired without a file being saved
Expand Down
12 changes: 12 additions & 0 deletions lib/watchr/event_handlers/unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize(path)
update_reference_times
end

# File's path as a Pathname
def pathname
@pathname ||= Pathname(@path)
end
Expand All @@ -36,6 +37,17 @@ def update_reference_times
@reference_ctime = pathname.ctime
end

# Type of latest event.
#
# A single type is determined, even though more than one stat times may
# have changed on the file. The type is the first to match in the
# following hierarchy:
#
# :deleted, :modified (mtime), :accessed (atime), :changed (ctime)
#
# ===== Returns
# type<Symbol>:: latest event's type
#
def type
return :deleted if !pathname.exist?
return :modified if pathname.mtime > @reference_mtime
Expand Down
11 changes: 6 additions & 5 deletions lib/watchr/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ def parse!
instance_eval(@path.read)
end

def reset
@default_action = lambda {}
@rules.clear
end

# Find an action corresponding to a path and event type. The returned
# action is actually a wrapper around the rule's action, with the
# match_data prepopulated.
Expand Down Expand Up @@ -200,5 +195,11 @@ def rules_for(path)
def rel_path(path)
Pathname(path).expand_path.relative_path_from(Pathname(Dir.pwd))
end

# Reset script state
def reset
@default_action = lambda {}
@rules.clear
end
end
end

0 comments on commit 85bf997

Please sign in to comment.