aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2015-11-12 01:52:36 +0100
committerXavier Noria <fxn@hashref.com>2015-11-12 02:12:46 +0100
commit99c1043aa9a1ff81aa1eef6e957f7ebe89ff25f1 (patch)
treecaf48ab5d7180ac22518a20d4826cac2e2ec4ad2 /activesupport/lib
parent7d242be5a4fbfaea2d585905d76cc6bae45cbe77 (diff)
downloadrails-99c1043aa9a1ff81aa1eef6e957f7ebe89ff25f1.tar.gz
rails-99c1043aa9a1ff81aa1eef6e957f7ebe89ff25f1.tar.bz2
rails-99c1043aa9a1ff81aa1eef6e957f7ebe89ff25f1.zip
base (refined) Pathname#ascendant_of? also on Pathname#ascend
A small rewrite in a last attempt at writing obvious and portable code without manual string manipulation. Note that Pathname#== uses string comparison on Windows, so if client code passes "C:\foo" and "c:/foo/bar" the predicate won't see the former is an ascendant of the latter. Risky business.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/file_evented_update_checker.rb9
1 files changed, 2 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/file_evented_update_checker.rb b/activesupport/lib/active_support/file_evented_update_checker.rb
index 5e5874c014..638458c6ce 100644
--- a/activesupport/lib/active_support/file_evented_update_checker.rb
+++ b/activesupport/lib/active_support/file_evented_update_checker.rb
@@ -79,13 +79,8 @@ module ActiveSupport
using Module.new {
refine Pathname do
def ascendant_of?(other)
- if self != other && other.to_s.start_with?(to_s)
- # On Windows each_filename does not include the drive letter,
- # but the test above already detects if they differ.
- parts = each_filename.to_a
- other_parts = other.each_filename.to_a
-
- other_parts[0, parts.length] == parts
+ self != other && other.ascend do |ascendant|
+ break true if self == ascendant
end
end
end