diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-10 11:52:13 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-10 11:52:23 -0700 |
commit | 35864db96132a820ce1c4a67dbac5e656a5b8489 (patch) | |
tree | 6f7a348333b8808280d84b750061f409c6cdbe74 /actionview/lib/action_view | |
parent | 7b9e0f53c7bd5d3db1bdcd79e787612b2ac85d98 (diff) | |
download | rails-35864db96132a820ce1c4a67dbac5e656a5b8489.tar.gz rails-35864db96132a820ce1c4a67dbac5e656a5b8489.tar.bz2 rails-35864db96132a820ce1c4a67dbac5e656a5b8489.zip |
feature detect for FNM_EXTGLOB for older Ruby. Fixes #15053
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r-- | actionview/lib/action_view/template/resolver.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index dbfabef15d..189086132e 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -181,11 +181,7 @@ module ActionView def query(path, details, formats) query = build_query(path, details) - template_paths = Dir[query].reject { |filename| - File.directory?(filename) || - # deals with case-insensitive file systems. - !File.fnmatch(query, filename, File::FNM_EXTGLOB) - } + template_paths = find_template_paths query template_paths.map { |template| handler, format, variant = extract_handler_and_format_and_variant(template, formats) @@ -200,6 +196,26 @@ module ActionView } end + if File.const_defined? :FNM_EXTGLOB + def find_template_paths(query) + Dir[query].reject { |filename| + File.directory?(filename) || + # deals with case-insensitive file systems. + !File.fnmatch(query, filename, File::FNM_EXTGLOB) + } + end + else + def find_template_paths(query) + # deals with case-insensitive file systems. + sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] } + + Dir[query].reject { |filename| + File.directory?(filename) || + !sanitizer[File.dirname(filename)].include?(filename) + } + end + end + # Helper for building query glob string based on resolver's pattern. def build_query(path, details) query = @pattern.dup |