Commit d24245fc authored by Fabio Pelosin's avatar Fabio Pelosin

[PathList] Fix #relative_glob and clean up the code

parent b81d16f1
...@@ -53,6 +53,12 @@ module Pod ...@@ -53,6 +53,12 @@ module Pod
@dirs = dirs.map { |d| d.gsub(/\/\.\.?$/,'') }.uniq @dirs = dirs.map { |d| d.gsub(/\/\.\.?$/,'') }.uniq
end end
#-----------------------------------------------------------------------#
public
# @!group Globbing
# @return [Array<Pathname>] Similar to {glob} but returns the absolute # @return [Array<Pathname>] Similar to {glob} but returns the absolute
# paths. # paths.
# #
...@@ -89,11 +95,17 @@ module Pod ...@@ -89,11 +95,17 @@ module Pod
end end
end.flatten end.flatten
list = list.map { |path| Pathname.new(path) }
list -= relative_glob(exclude_patterns) if exclude_patterns list -= relative_glob(exclude_patterns) if exclude_patterns
list
list.map { |path| Pathname.new(path) }
end end
#-----------------------------------------------------------------------#
private
# @!group Private helpers
# @return [Bool] Wether a path is a directory. The result of this method # @return [Bool] Wether a path is a directory. The result of this method
# computed without accessing the file system and is case # computed without accessing the file system and is case
# insensitive. # insensitive.
...@@ -125,7 +137,7 @@ module Pod ...@@ -125,7 +137,7 @@ module Pod
# @param [String] pattern A {Dir#glob} like pattern. # @param [String] pattern A {Dir#glob} like pattern.
# #
def dir_glob_equivalent_patterns(pattern) def dir_glob_equivalent_patterns(pattern)
pattern.gsub('/**/', '{/**/,/}') pattern = pattern.gsub('/**/', '{/**/,/}')
values_by_set = {} values_by_set = {}
pattern.scan(/\{[^}]*\}/) do |set| pattern.scan(/\{[^}]*\}/) do |set|
values = set.gsub(/[{}]/, '').split(',') values = set.gsub(/[{}]/, '').split(',')
......
require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../spec_helper', __FILE__)
describe Pod::LocalPod::PathList do module Pod
describe LocalPod::PathList do
before do before do
@path_list = Pod::LocalPod::PathList.new(fixture('banana-lib')) @path_list = LocalPod::PathList.new(fixture('banana-lib'))
end end
describe "In general" do
it "creates the list of all the files" do it "creates the list of all the files" do
files = @path_list.files files = @path_list.files
files.reject! do |f| files.reject! do |f|
...@@ -16,15 +19,17 @@ describe Pod::LocalPod::PathList do ...@@ -16,15 +19,17 @@ describe Pod::LocalPod::PathList do
Classes/Banana.h Classes/Banana.h
Classes/Banana.m Classes/Banana.m
Classes/BananaLib.pch Classes/BananaLib.pch
Classes/BananaPrivate.h
README README
Resources/logo-sidebar.png Resources/logo-sidebar.png
preserve_me.txt
sub-dir/sub-dir-2/somefile.txt sub-dir/sub-dir-2/somefile.txt
] ]
files.sort.should == expected files.sort.should == expected
end end
it "creates theh list of the directories" do it "creates the list of the directories" do
dirs = @path_list.dirs dirs = @path_list.dirs
dirs.reject! do |f| dirs.reject! do |f|
f.include?('libPusher') || f.include?('.git') f.include?('libPusher') || f.include?('.git')
...@@ -32,27 +37,47 @@ describe Pod::LocalPod::PathList do ...@@ -32,27 +37,47 @@ describe Pod::LocalPod::PathList do
dirs.sort.should == %w| Classes Resources sub-dir sub-dir/sub-dir-2 | dirs.sort.should == %w| Classes Resources sub-dir sub-dir/sub-dir-2 |
end end
it "detects a directory" do
@path_list.directory?('classes').should == true
end end
it "doesn't reports as a directory a file" do #-------------------------------------------------------------------------#
@path_list.directory?('Classes/Banana.m').should == false
end describe "Globbing" do
it "can glob the root for a given pattern" do it "can glob the root for a given pattern" do
paths = @path_list.relative_glob('Classes/*.{h,m}').map(&:to_s) paths = @path_list.relative_glob('Classes/*.{h,m}').map(&:to_s)
paths.sort.should == %w| Classes/Banana.h Classes/Banana.m | paths.sort.should == %w[
Classes/Banana.h
Classes/Banana.m
Classes/BananaPrivate.h
]
end end
it "supports the `**` glob pattern" do it "supports the `**` glob pattern" do
paths = @path_list.relative_glob('Classes/**/*.{h,m}').map(&:to_s) paths = @path_list.relative_glob('Classes/**/*.{h,m}').map(&:to_s)
paths.sort.should == %w| Classes/Banana.h Classes/Banana.m | paths.sort.should == %w[
Classes/Banana.h
Classes/Banana.m
Classes/BananaPrivate.h
]
end end
it "supports an optional pattern for globbing directories" do it "supports an optional pattern for globbing directories" do
paths = @path_list.relative_glob('Classes', '*.{h,m}').map(&:to_s) paths = @path_list.relative_glob('Classes', '*.{h,m}').map(&:to_s)
paths.sort.should == %w| Classes/Banana.h Classes/Banana.m | paths.sort.should == %w[
Classes/Banana.h
Classes/Banana.m
Classes/BananaPrivate.h
]
end
it "supports an optional list of patterns to exclude" do
exclude_patterns = ['**/*.m', '**/*Private*.*']
paths = @path_list.relative_glob('Classes/*', nil, exclude_patterns).map(&:to_s)
paths.sort.should == %w[
Classes/Banana.h
Classes/BananaLib.pch
]
end end
it "can return the absolute paths from glob" do it "can return the absolute paths from glob" do
...@@ -64,24 +89,52 @@ describe Pod::LocalPod::PathList do ...@@ -64,24 +89,52 @@ describe Pod::LocalPod::PathList do
paths = @path_list.relative_glob('Classes/*.{h,m}') paths = @path_list.relative_glob('Classes/*.{h,m}')
paths.any? { |p| p.absolute? }.should == false paths.any? { |p| p.absolute? }.should == false
end end
end
#-------------------------------------------------------------------------#
describe "Private Helpers" do
describe "#directory?" do
it "detects a directory" do
@path_list.send(:directory?, 'classes').should == true
end
it "doesn't reports as a directory a file" do
@path_list.send(:directory?, 'Classes/Banana.m').should == false
end
end
describe "#directory?" do
it "expands a pattern into all the combinations of Dir#glob literals" do it "expands a pattern into all the combinations of Dir#glob literals" do
patterns = @path_list.dir_glob_equivalent_patterns('{file1,file2}.{h,m}') patterns = @path_list.send(:dir_glob_equivalent_patterns, '{file1,file2}.{h,m}')
patterns.sort.should == %w| file1.h file1.m file2.h file2.m | patterns.sort.should == %w[ file1.h file1.m file2.h file2.m ]
end end
it "returns the original pattern if there are no Dir#glob expansions" do it "returns the original pattern if there are no Dir#glob expansions" do
patterns = @path_list.dir_glob_equivalent_patterns('file*.*') patterns = @path_list.send(:dir_glob_equivalent_patterns, 'file*.*')
patterns.sort.should == %w| file*.* | patterns.sort.should == %w[ file*.* ]
end end
it "expands `**`" do it "expands `**`" do
patterns = @path_list.dir_glob_equivalent_patterns('Classes/**/file.m') patterns = @path_list.send(:dir_glob_equivalent_patterns, 'Classes/**/file.m')
patterns.sort.should == %w| Classes/**/file.m Classes/file.m | patterns.sort.should == %w[ Classes/**/file.m Classes/file.m ]
end end
it "supports a combination of `**` and literals" do it "supports a combination of `**` and literals" do
patterns = @path_list.dir_glob_equivalent_patterns('Classes/**/file.{h,m}') patterns = @path_list.send(:dir_glob_equivalent_patterns, 'Classes/**/file.{h,m}')
patterns.sort.should == %w| Classes/**/file.h Classes/**/file.m Classes/file.h Classes/file.m | patterns.sort.should == %w[
Classes/**/file.h
Classes/**/file.m
Classes/file.h
Classes/file.m
]
end
end
end
#-------------------------------------------------------------------------#
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment