Class: ActiveSupport::EventedFileUpdateChecker::PathHelper
- Defined in:
- lib/active_support/evented_file_update_checker.rb
Instance Method Summary collapse
-
#existing_parent(dir) ⇒ Object
Returns the deepest existing ascendant, which could be the argument itself.
-
#filter_out_descendants(dirs) ⇒ Object
Filters out directories which are descendants of others in the collection (stable).
-
#longest_common_subpath(paths) ⇒ Object
Given a collection of Pathname objects returns the longest subpath common to all of them, or
nil
if there is none. - #normalize_extension(ext) ⇒ Object
- #xpath(path) ⇒ Object
Instance Method Details
#existing_parent(dir) ⇒ Object
Returns the deepest existing ascendant, which could be the argument itself.
160 161 162 163 164 |
# File 'lib/active_support/evented_file_update_checker.rb', line 160 def existing_parent(dir) dir.ascend do |ascendant| break ascendant if ascendant.directory? end end |
#filter_out_descendants(dirs) ⇒ Object
Filters out directories which are descendants of others in the collection (stable).
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/active_support/evented_file_update_checker.rb', line 167 def filter_out_descendants(dirs) return dirs if dirs.length < 2 dirs_sorted_by_nparts = dirs.sort_by { |dir| dir.each_filename.to_a.length } descendants = [] until dirs_sorted_by_nparts.empty? dir = dirs_sorted_by_nparts.shift dirs_sorted_by_nparts.reject! do |possible_descendant| ascendant_of?(dir, possible_descendant) && descendants << possible_descendant end end # Array#- preserves order. dirs - descendants end |
#longest_common_subpath(paths) ⇒ Object
Given a collection of Pathname objects returns the longest subpath common to all of them, or nil
if there is none.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/active_support/evented_file_update_checker.rb', line 138 def longest_common_subpath(paths) return if paths.empty? lcsp = Pathname.new(paths[0]) paths[1..-1].each do |path| until ascendant_of?(lcsp, path) if lcsp.root? # If we get here a root directory is not an ascendant of path. # This may happen if there are paths in different drives on # Windows. return else lcsp = lcsp.parent end end end lcsp end |
#normalize_extension(ext) ⇒ Object
132 133 134 |
# File 'lib/active_support/evented_file_update_checker.rb', line 132 def normalize_extension(ext) ext.to_s.sub(/\A\./, '') end |
#xpath(path) ⇒ Object
128 129 130 |
# File 'lib/active_support/evented_file_update_checker.rb', line 128 def xpath(path) Pathname.new(path). end |