mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Merge pull request #460 from crystal-ameba/fix-issue-459
Make sure we only return files from `GlobUtils#expand` method
This commit is contained in:
commit
6d03cef6df
2 changed files with 16 additions and 9 deletions
|
@ -1,11 +1,7 @@
|
||||||
require "../spec_helper"
|
require "../spec_helper"
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
struct GlobUtilsClass
|
subject = GlobUtils
|
||||||
include GlobUtils
|
|
||||||
end
|
|
||||||
|
|
||||||
subject = GlobUtilsClass.new
|
|
||||||
current_file_basename = File.basename(__FILE__)
|
current_file_basename = File.basename(__FILE__)
|
||||||
current_file_path = "spec/ameba/#{current_file_basename}"
|
current_file_path = "spec/ameba/#{current_file_basename}"
|
||||||
|
|
||||||
|
@ -45,6 +41,12 @@ module Ameba
|
||||||
subject.expand(["**/#{current_file_basename}", "**/#{current_file_basename}"])
|
subject.expand(["**/#{current_file_basename}", "**/#{current_file_basename}"])
|
||||||
.should eq [current_file_path]
|
.should eq [current_file_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not list folders" do
|
||||||
|
subject.expand(["**/*"]).each do |path|
|
||||||
|
fail "#{path.inspect} should be a file" unless File.file?(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
module Ameba
|
module Ameba
|
||||||
# Helper module that is utilizes helpers for working with globs.
|
# Helper module that is utilizes helpers for working with globs.
|
||||||
module GlobUtils
|
module GlobUtils
|
||||||
|
extend self
|
||||||
|
|
||||||
# Returns all files that match specified globs.
|
# Returns all files that match specified globs.
|
||||||
# Globs can have wildcards or be rejected:
|
# Globs can have wildcards or be rejected:
|
||||||
#
|
#
|
||||||
|
@ -20,10 +22,13 @@ module Ameba
|
||||||
# expand(["spec/*.cr", "src"]) # => all files in src folder + first level specs
|
# expand(["spec/*.cr", "src"]) # => all files in src folder + first level specs
|
||||||
# ```
|
# ```
|
||||||
def expand(globs)
|
def expand(globs)
|
||||||
globs.flat_map do |glob|
|
globs
|
||||||
|
.flat_map do |glob|
|
||||||
glob += "/**/*.cr" if File.directory?(glob)
|
glob += "/**/*.cr" if File.directory?(glob)
|
||||||
Dir[glob]
|
Dir[glob]
|
||||||
end.uniq!
|
end
|
||||||
|
.uniq!
|
||||||
|
.select! { |path| File.file?(path) }
|
||||||
end
|
end
|
||||||
|
|
||||||
private def rejected_globs(globs)
|
private def rejected_globs(globs)
|
||||||
|
|
Loading…
Reference in a new issue