Commit 7d9479c1 authored by Eloy Duran's avatar Eloy Duran

Allow the use of the Rake FileList class for source_files, clean_paths, and resources. Fixes #65.

parent ece1c9fd
......@@ -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
......
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
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
......
Subproject commit 39e348b0bfd268fe0a8606e71a07a0f9071cf7eb
Subproject commit 56c5f468351fe0e195ee95a78160f4c18eaec40b
......@@ -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) }
......
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