mirror of
https://github.com/zhigang1992/CocoaPods.git
synced 2026-04-30 10:22:26 +08:00
Allow the use of the Rake FileList class for source_files, clean_paths, and resources. Fixes #65.
This commit is contained in:
1
Rakefile
1
Rakefile
@@ -81,6 +81,7 @@ namespace :examples do
|
||||
require 'pathname'
|
||||
result = []
|
||||
examples = Pathname.new(File.expand_path('../examples', __FILE__))
|
||||
return [examples + ENV['example']] if ENV['example']
|
||||
examples.entries.each do |example|
|
||||
next if %w{ . .. }.include?(example.basename.to_s)
|
||||
example = examples + example
|
||||
|
||||
@@ -19,6 +19,7 @@ module Pod
|
||||
autoload :Version, 'cocoapods/version'
|
||||
|
||||
autoload :Pathname, 'pathname'
|
||||
autoload :FileList, 'cocoapods/file_list'
|
||||
end
|
||||
|
||||
module Xcodeproj
|
||||
|
||||
34
lib/cocoapods/file_list.rb
Normal file
34
lib/cocoapods/file_list.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
require 'rake'
|
||||
|
||||
# This makes Rake::FileList usable with the Specification attributes
|
||||
# source_files, clean_paths, and resources.
|
||||
|
||||
module Rake
|
||||
class FileList
|
||||
def prepend_patterns(pathname)
|
||||
@pending_add.map! { |pattern| (pathname + pattern).to_s }
|
||||
end
|
||||
|
||||
def directory?
|
||||
false
|
||||
end
|
||||
|
||||
def glob
|
||||
to_a.map { |path| Pathname.new(path) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Pathname
|
||||
alias_method :_original_sum, :+
|
||||
def +(other)
|
||||
if other.is_a?(Rake::FileList)
|
||||
other.prepend_patterns(self)
|
||||
other
|
||||
else
|
||||
_original_sum(other)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,34 +1,3 @@
|
||||
require 'rake'
|
||||
|
||||
module Rake
|
||||
class FileList
|
||||
def prepend_patterns(pathname)
|
||||
@pending_add.map! { |pattern| (pathname + pattern).to_s }
|
||||
end
|
||||
|
||||
# This makes Rake::FileList usable with source_files and clean_paths.
|
||||
def directory?
|
||||
false
|
||||
end
|
||||
|
||||
def glob
|
||||
to_a.map { |path| Pathname.new(path) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Pathname
|
||||
alias_method :_original_sum, :+
|
||||
def +(other)
|
||||
if other.is_a?(Rake::FileList)
|
||||
other.prepend_patterns(self)
|
||||
other
|
||||
else
|
||||
_original_sum(other)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Pod
|
||||
extend Config::Mixin
|
||||
|
||||
@@ -99,30 +68,18 @@ module Pod
|
||||
end
|
||||
|
||||
def source_files=(patterns)
|
||||
if !patterns.is_a?(Rake::FileList) && patterns.is_a?(Array)
|
||||
@source_files = patterns
|
||||
else
|
||||
@source_files = [patterns]
|
||||
end
|
||||
@source_files = pattern_list(patterns)
|
||||
end
|
||||
attr_reader :source_files
|
||||
|
||||
def resources=(patterns)
|
||||
if !patterns.is_a?(Rake::FileList) && patterns.is_a?(Array)
|
||||
@resources = patterns
|
||||
else
|
||||
@resources = [patterns]
|
||||
end
|
||||
@resources = pattern_list(patterns)
|
||||
end
|
||||
attr_reader :resources
|
||||
alias_method :resource=, :resources=
|
||||
|
||||
def clean_paths=(patterns)
|
||||
if !patterns.is_a?(Rake::FileList) && patterns.is_a?(Array)
|
||||
@clean_paths = patterns
|
||||
else
|
||||
@clean_paths = [patterns]
|
||||
end
|
||||
@clean_paths = pattern_list(patterns)
|
||||
end
|
||||
attr_reader :clean_paths
|
||||
alias_method :clean_path=, :clean_paths=
|
||||
@@ -222,6 +179,14 @@ module Pod
|
||||
false
|
||||
end
|
||||
|
||||
def pattern_list(patterns)
|
||||
if patterns.is_a?(Array) && (!defined?(Rake) || !patterns.is_a?(Rake::FileList))
|
||||
patterns
|
||||
else
|
||||
[patterns]
|
||||
end
|
||||
end
|
||||
|
||||
# Returns all resource files of this pod, but relative to the
|
||||
# project pods root.
|
||||
def expanded_resources
|
||||
|
||||
2
spec/fixtures/spec-repos/master
vendored
2
spec/fixtures/spec-repos/master
vendored
Submodule spec/fixtures/spec-repos/master updated: 39e348b0bf...56c5f46835
@@ -4,10 +4,6 @@ describe "Pod::Command" do
|
||||
extend SpecHelper::Git
|
||||
extend SpecHelper::TemporaryDirectory
|
||||
|
||||
before do
|
||||
fixture('spec-repos/master') # ensure the archive is unpacked
|
||||
end
|
||||
|
||||
it "creates the local spec-repos directory and creates a clone of the `master' repo" do
|
||||
command = Pod::Command.parse('setup', '--silent')
|
||||
def command.master_repo_url; SpecHelper.fixture('spec-repos/master'); end
|
||||
|
||||
@@ -37,7 +37,7 @@ describe "Pod::Downloader" do
|
||||
:git => fixture('banana-lib'), :tag => 'v1.0'
|
||||
)
|
||||
downloader.download
|
||||
downloader.clean(['README'])
|
||||
downloader.clean([@dir + 'README'])
|
||||
(@dir + 'README').should.not.exist
|
||||
end
|
||||
end
|
||||
|
||||
@@ -273,7 +273,7 @@ describe "A Pod::Specification, in general," do
|
||||
end
|
||||
|
||||
it "takes any object for clean_paths as long as it responds to #glob (we provide this for Rake::FileList)" do
|
||||
require 'rake'
|
||||
Pod::FileList # autoload
|
||||
@spec.clean_paths = FileList['*'].exclude('Rakefile')
|
||||
list = ROOT + @spec.clean_paths.first
|
||||
list.glob.should == FileList[(ROOT + '*').to_s].exclude('Rakefile').map { |path| Pathname.new(path) }
|
||||
|
||||
Reference in New Issue
Block a user