Commit 992ecf20 authored by Eloy Duran's avatar Eloy Duran

Use real Ruby accessor writer and reader methods.

parent 39d16c07
dependency 'AFNetworking'
dependency 'JSONKit'
dependency 'FormatterKit'
......@@ -26,7 +26,7 @@ module Pod
def run
Source.search_by_name(@query.strip, @full_text_search).each do |set|
puts "==> #{set.name} (#{set.versions.reverse.join(", ")})"
puts " #{set.specification.read(:summary).strip}"
puts " #{set.specification.summary.strip}"
puts
end
end
......
......@@ -31,24 +31,23 @@ module Pod
author = `git config --get user.name`.strip
email = `git config --get user.email`.strip
spec = <<-SPEC.gsub(/^ /, '')
Pod::Spec.new do
name '#{@name}'
version '1.0.0'
summary 'A short description of #{@name}.'
homepage 'http://example.com/#{@name}'
author '#{author}' => '#{email}'
source :git => 'http://example.com/#{@name}.git',
:tag => '1.0.0'
Pod::Spec.new do |s|
s.name = '#{@name}'
s.version = '1.0.0'
s.summary = 'A short description of #{@name}.'
s.homepage = 'http://example.com/#{@name}'
s.author = { '#{author}' => '#{email}' }
s.source = { :git => 'http://example.com/#{@name}.git', :tag => '1.0.0' }
description 'An optional longer description of #{@name}.'
s.description = 'An optional longer description of #{@name}.'
# A list of file patterns. If the pattern is a directory then the path will
# automatically have '*.{h,m,mm,c,cpp' appended.
source_files 'Classes', 'Classes/**/*.{h,m}'
s.source_files = 'Classes', 'Classes/**/*.{h,m}'
xcconfig 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework' }
dependency 'SomeLibraryThat#{@name}DependsOn', '>= 1.0.0'
s.dependency 'SomeLibraryThat#{@name}DependsOn', '>= 1.0.0'
end
SPEC
(Pathname.pwd + "#{@name}.podspec").open('w') { |f| f << spec }
......
......@@ -20,7 +20,7 @@ module Pod
source_files = []
build_specification_sets.each do |set|
spec = set.specification
spec.read(:source_files).each do |pattern|
spec.source_files.each do |pattern|
pattern = spec.pod_destroot + pattern
pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
pattern.glob.each do |file|
......@@ -48,7 +48,7 @@ module Pod
def generate_project
source_files.each { |file| xcodeproj.add_source_file(file) }
build_specification_sets.each do |set|
xcconfig << set.specification.read(:xcconfig)
xcconfig << set.specification.xcconfig
end
end
......
......@@ -11,7 +11,7 @@ module Pod
end
def find_dependency_sets(specification)
specification.read(:dependencies).each do |dependency|
specification.dependencies.each do |dependency|
set = Source.search(dependency)
set.required_by(specification)
unless @sets.include?(set)
......
......@@ -48,7 +48,7 @@ module Pod
pod_sets.map do |set|
text = if full_text_search
s = set.specification
"#{s.read(:name)} #{s.read(:summary)} #{s.read(:description)}"
"#{s.name} #{s.summary} #{s.description}"
else
set.name
end
......
......@@ -19,88 +19,81 @@ module Pod
attr_accessor :defined_in_file
def initialize(&block)
def initialize
@dependencies = []
@xcconfig = Xcode::Config.new
instance_eval(&block) if block_given?
yield self if block_given?
end
# Attributes
def read(name)
instance_variable_get("@#{name}")
end
def name(name)
@name = name
end
attr_accessor :name
attr_accessor :homepage
attr_accessor :description
attr_accessor :source
def version(version)
attr_reader :version
def version=(version)
@version = Version.new(version)
end
def authors(*names_and_email_addresses)
list = names_and_email_addresses
def authors=(*names_and_email_addresses)
list = names_and_email_addresses.flatten
unless list.first.is_a?(Hash)
authors = list.last.is_a?(Hash) ? list.pop : {}
list.each { |name| authors[name] = nil }
end
@authors = authors || list.first
end
alias_method :author, :authors
alias_method :author=, :authors=
attr_reader :authors
def homepage(url)
@homepage = url
end
def summary(summary)
def summary=(summary)
@summary = summary
@description ||= summary
end
attr_reader :summary
def description(description)
@description = description
end
def part_of(name, *version_requirements)
part_of_dependency(name, *version_requirements)
def part_of=(*name_and_version_requirements)
self.part_of_dependency = *name_and_version_requirements
@part_of.only_part_of_other_pod = true
end
attr_reader :part_of
def part_of_dependency(name, *version_requirements)
@part_of = dependency(name, *version_requirements)
end
def source_files(*patterns)
@source_files = patterns.map { |p| Pathname.new(p) }
def part_of_dependency=(*name_and_version_requirements)
@part_of = dependency(*name_and_version_requirements)
end
def source(remote)
@source = remote
def source_files=(*patterns)
@source_files = patterns.flatten.map { |p| Pathname.new(p) }
end
attr_reader :source_files
attr_reader :dependencies
def dependency(name, *version_requirements)
def dependency(*name_and_version_requirements)
name, *version_requirements = name_and_version_requirements.flatten
dep = Dependency.new(name, *version_requirements)
@dependencies << dep
dep
end
attr_reader :dependencies
def xcconfig(hash)
def xcconfig=(hash)
@xcconfig.merge!(hash)
end
attr_reader :xcconfig
def frameworks(*frameworks)
def frameworks=(*frameworks)
frameworks.unshift('')
xcconfig 'OTHER_LDFLAGS' => frameworks.join(' -framework ').strip
self.xcconfig = { 'OTHER_LDFLAGS' => frameworks.join(' -framework ').strip }
end
alias_method :framework, :frameworks
alias_method :framework=, :frameworks=
def libraries(*libraries)
def libraries=(*libraries)
libraries.unshift('')
xcconfig 'OTHER_LDFLAGS' => libraries.join(' -l ').strip
self.xcconfig = { 'OTHER_LDFLAGS' => libraries.join(' -l ').strip }
end
alias_method :library, :libraries
alias_method :library=, :libraries=
# Not attributes
......@@ -108,8 +101,8 @@ module Pod
def ==(other)
self.class === other &&
@name && @name == other.read(:name) &&
@version && @version == other.read(:version)
@name && @name == other.name &&
@version && @version == other.version
end
def dependency_by_name(name)
......
......@@ -44,16 +44,16 @@ describe "Pod::Command" do
end
path = temporary_directory + 'Bananas.podspec'
spec = Pod::Specification.from_podspec(path)
spec.read(:name).should == 'Bananas'
spec.read(:version).should == Pod::Version.new('1.0.0')
spec.read(:summary).should == 'A short description of Bananas.'
spec.read(:homepage).should == 'http://example.com/Bananas'
spec.read(:authors).should == { `git config --get user.name`.strip => `git config --get user.email`.strip }
spec.read(:source).should == { :git => 'http://example.com/Bananas.git', :tag => '1.0.0' }
spec.read(:description).should == 'An optional longer description of Bananas.'
spec.read(:source_files).should == [Pathname.new('Classes'), Pathname.new('Classes/**/*.{h,m}')]
spec.read(:xcconfig).to_hash.should == { 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework' }
spec.read(:dependencies).should == [Pod::Dependency.new('SomeLibraryThatBananasDependsOn', '>= 1.0.0')]
spec.name.should == 'Bananas'
spec.version.should == Pod::Version.new('1.0.0')
spec.summary.should == 'A short description of Bananas.'
spec.homepage.should == 'http://example.com/Bananas'
spec.authors.should == { `git config --get user.name`.strip => `git config --get user.email`.strip }
spec.source.should == { :git => 'http://example.com/Bananas.git', :tag => '1.0.0' }
spec.description.should == 'An optional longer description of Bananas.'
spec.source_files.should == [Pathname.new('Classes'), Pathname.new('Classes/**/*.{h,m}')]
spec.xcconfig.to_hash.should == { 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework' }
spec.dependencies.should == [Pod::Dependency.new('SomeLibraryThatBananasDependsOn', '>= 1.0.0')]
end
before do
......@@ -77,7 +77,7 @@ describe "Pod::Command" do
"images and stylesheets.\n\n" \
"==> JSONKit (1.4)\n" \
" A Very High Performance Objective-C JSON Library.\n\n" \
"==> SSZipArchive (1.0)\n" \
"==> SSZipArchive (0.1.0)\n" \
" Utility class for unzipping files on iOS and Mac.\n\n"
],
[
......@@ -110,7 +110,7 @@ describe "Pod::Command" do
"Mac OS X and iPhone\n\n" \
"==> Reachability (2.0.4)\n" \
" A wrapper for the SystemConfiguration Reachablity APIs.\n\n" \
"==> SSZipArchive (1.0)\n" \
"==> SSZipArchive (0.1.0)\n" \
" Utility class for unzipping files on iOS and Mac.\n\n"
]
].each do |query, result|
......
......@@ -9,9 +9,9 @@ module SpecHelper
def set.specification
spec = super
unless spec.part_of_other_pod?
source = spec.read(:source)
source[:git] = SpecHelper.fixture("integration/#{spec.read(:name)}").to_s
spec.source(source)
source = spec.source
source[:git] = SpecHelper.fixture("integration/#{spec.name}").to_s
spec.source = source
end
spec
end
......@@ -48,10 +48,10 @@ else
# TODO add a simple source file which uses the compiled lib to check that it really really works
it "should activate required pods and create a working static library xcode project" do
spec = Pod::Spec.new do
dependency 'ASIWebPageRequest', '>= 1.8.1'
dependency 'JSONKit', '>= 1.0'
dependency 'SSZipArchive', '< 2'
spec = Pod::Spec.new do |s|
s.dependency 'ASIWebPageRequest', '>= 1.8.1'
s.dependency 'JSONKit', '>= 1.0'
s.dependency 'SSZipArchive', '< 2'
end
installer = SpecHelper::Installer.new(spec)
......@@ -69,15 +69,16 @@ else
project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s
NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.xcodeproj.to_hash
puts "\n[!] Compiling static library..."
Dir.chdir(config.project_pods_root) do
system("xcodebuild > /dev/null 2>&1").should == true
end
#puts "\n[!] Compiling static library..."
#Dir.chdir(config.project_pods_root) do
#system("xcodebuild > /dev/null 2>&1").should == true
#system("xcodebuild").should == true
#end
end
it "does not activate pods that are only part of other pods" do
spec = Pod::Spec.new do
dependency 'Reachability'
spec = Pod::Spec.new do |s|
s.dependency 'Reachability'
end
installer = SpecHelper::Installer.new(spec)
......@@ -89,16 +90,16 @@ else
# TODO we need to do more cleaning and/or add a --prune task
it "overwrites an existing project.pbxproj file" do
spec = Pod::Spec.new do
dependency 'JSONKit'
spec = Pod::Spec.new do |s|
s.dependency 'JSONKit'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
Pod::Source.reset!
Pod::Spec::Set.reset!
spec = Pod::Spec.new do
dependency 'SSZipArchive'
spec = Pod::Spec.new do |s|
s.dependency 'SSZipArchive'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
......
......@@ -22,7 +22,7 @@ describe "Pod::Installer" do
"USER_HEADER_SEARCH_PATHS" => "$(BUILT_PRODUCTS_DIR)/Pods",
"ALWAYS_SEARCH_USER_PATHS" => "YES",
"OTHER_LDFLAGS" => "-framework SystemConfiguration -framework CFNetwork " \
"-framework MobileCoreServices -l z.1.2.3"
"-framework MobileCoreServices -l z.1"
}
],
[
......@@ -43,13 +43,13 @@ describe "Pod::Installer" do
"ALWAYS_SEARCH_USER_PATHS" => "YES",
"HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2",
"OTHER_LDFLAGS" => "-l xml2.2.7.3 -framework SystemConfiguration " \
"-framework CFNetwork -framework MobileCoreServices -l z.1.2.3"
"-framework CFNetwork -framework MobileCoreServices -l z.1"
}
],
].each do |name, patterns, expected_pattern, xcconfig|
Pod::Source.reset!
Pod::Spec::Set.reset!
installer = Pod::Installer.new(Pod::Spec.new { dependency(name); source_files(*patterns) })
installer = Pod::Installer.new(Pod::Spec.new { |s| s.dependency(name); s.source_files = *patterns })
expected = (stubbed_destroot(installer) + expected_pattern).glob.map do |file|
file.relative_path_from(config.project_pods_root)
end
......
......@@ -15,7 +15,7 @@ describe "Pod::Resolver" do
sets << Pod::Spec::Set.by_pod_dir(fixture('spec-repos/master/Reachability'))
sets << Pod::Spec::Set.by_pod_dir(fixture('spec-repos/master/ASIHTTPRequest'))
sets << Pod::Spec::Set.by_pod_dir(fixture('spec-repos/master/ASIWebPageRequest'))
resolver = Pod::Resolver.new(Pod::Spec.new { dependency 'ASIWebPageRequest' })
resolver = Pod::Resolver.new(Pod::Spec.new { |s| s.dependency 'ASIWebPageRequest' })
resolver.resolve.sort_by(&:name).should == sets.sort_by(&:name)
end
end
......
......@@ -34,23 +34,23 @@ describe "Pod::Specification::Set" do
end
it "checks if the dependency of the specification is compatible with existing requirements" do
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '1.8' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8.1' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '> 1.7.9' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '~> 1.8.0' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest', '1.8' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest', '< 1.8.1' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest', '> 1.7.9' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest', '~> 1.8.0' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest' })
lambda {
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest', '< 1.8' })
}.should.raise Pod::Informative
end
it "raises if the required version doesn't exist" do
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest', '< 1.8' })
lambda { @set.required_version }.should.raise Pod::Informative
end
before do
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8.1' })
@set.required_by(Pod::Spec.new { |s| s.dependency 'ASIHTTPRequest', '< 1.8.1' })
end
it "returns the version required for the dependency" do
......@@ -62,18 +62,18 @@ describe "Pod::Specification::Set" do
end
it "returns the specification for the required version" do
@set.specification.should == Pod::Spec.new { name 'ASIHTTPRequest'; version '1.8' }
@set.specification.should == Pod::Spec.new { |s| s.name = 'ASIHTTPRequest'; s.version = '1.8' }
end
it "returns that this set is not only part for other pods" do
@set.required_by(Pod::Spec.new { part_of 'ASIHTTPRequest' })
@set.required_by(Pod::Spec.new { |s| s.part_of = 'ASIHTTPRequest' })
@set.should.not.be.only_part_of_other_pod
end
it "returns that this set is only part for other pods" do
@set.reset!
@set.required_by(Pod::Spec.new { part_of 'ASIHTTPRequest' })
@set.required_by(Pod::Spec.new { part_of 'ASIHTTPRequest' })
@set.required_by(Pod::Spec.new { |s| s.part_of = 'ASIHTTPRequest' })
@set.required_by(Pod::Spec.new { |s| s.part_of = 'ASIHTTPRequest' })
@set.should.be.only_part_of_other_pod
end
end
......@@ -45,41 +45,41 @@ describe "A Pod::Specification loaded from a podspec" do
end
it "returns the pod's name" do
@spec.read(:name).should == 'BananaLib'
@spec.name.should == 'BananaLib'
end
it "returns the pod's version" do
@spec.read(:version).should == Pod::Version.new('1.0')
@spec.version.should == Pod::Version.new('1.0')
end
it "returns a list of authors and their email addresses" do
@spec.read(:authors).should == {
@spec.authors.should == {
'Banana Corp' => nil,
'Monkey Boy' => 'monkey@banana-corp.local'
}
end
it "returns the pod's homepage" do
@spec.read(:homepage).should == 'http://banana-corp.local/banana-lib.html'
@spec.homepage.should == 'http://banana-corp.local/banana-lib.html'
end
it "returns the pod's summary" do
@spec.read(:summary).should == 'Chunky bananas!'
@spec.summary.should == 'Chunky bananas!'
end
it "returns the pod's description" do
@spec.read(:description).should == 'Full of chunky bananas.'
@spec.description.should == 'Full of chunky bananas.'
end
it "returns the pod's source" do
@spec.read(:source).should == {
@spec.source.should == {
:git => 'http://banana-corp.local/banana-lib.git',
:tag => 'v1.0'
}
end
it "returns the pod's source files" do
@spec.read(:source_files).should == [
@spec.source_files.should == [
Pathname.new('Classes/*.{h,m}'),
Pathname.new('Vendor')
]
......@@ -87,19 +87,19 @@ describe "A Pod::Specification loaded from a podspec" do
it "returns the pod's dependencies" do
expected = Pod::Dependency.new('monkey', '~> 1.0.1', '< 1.0.9')
@spec.read(:dependencies).should == [expected]
@spec.dependencies.should == [expected]
@spec.dependency_by_name('monkey').should == expected
end
it "returns the pod's xcconfig settings" do
@spec.read(:xcconfig).to_hash.should == {
@spec.xcconfig.to_hash.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration'
}
end
it "has a shortcut to add frameworks to the xcconfig" do
@spec.frameworks('CFNetwork', 'CoreText')
@spec.read(:xcconfig).to_hash.should == {
@spec.frameworks = 'CFNetwork', 'CoreText'
@spec.xcconfig.to_hash.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration ' \
'-framework CFNetwork ' \
'-framework CoreText'
......@@ -107,16 +107,16 @@ describe "A Pod::Specification loaded from a podspec" do
end
it "has a shortcut to add libraries to the xcconfig" do
@spec.libraries('z', 'xml2')
@spec.read(:xcconfig).to_hash.should == {
@spec.libraries = 'z', 'xml2'
@spec.xcconfig.to_hash.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration -l z -l xml2'
}
end
it "returns that it's equal to another specification if the name and version are equal" do
@spec.should == Pod::Spec.new { name 'BananaLib'; version '1.0' }
@spec.should.not == Pod::Spec.new { name 'OrangeLib'; version '1.0' }
@spec.should.not == Pod::Spec.new { name 'BananaLib'; version '1.1' }
@spec.should == Pod::Spec.new { |s| s.name = 'BananaLib'; s.version = '1.0' }
@spec.should.not == Pod::Spec.new { |s| s.name = 'OrangeLib'; s.version = '1.0' }
@spec.should.not == Pod::Spec.new { |s| s.name = 'BananaLib'; s.version = '1.1' }
@spec.should.not == Pod::Spec.new
end
......@@ -131,18 +131,18 @@ describe "A Pod::Specification that's part of another pod's source" do
end
it "adds a dependency on the other pod's source, but not the library" do
@spec.part_of 'monkey', '>= 1'
@spec.part_of = 'monkey', '>= 1'
@spec.should.be.part_of_other_pod
dep = Pod::Dependency.new('monkey', '>= 1')
@spec.read(:dependencies).should.not == [dep]
@spec.dependencies.should.not == [dep]
dep.only_part_of_other_pod = true
@spec.read(:dependencies).should == [dep]
@spec.dependencies.should == [dep]
end
it "adds a dependency on the other pod's source *and* the library" do
@spec.part_of_dependency 'monkey', '>= 1'
@spec.part_of_dependency = 'monkey', '>= 1'
@spec.should.be.part_of_other_pod
@spec.read(:dependencies).should == [Pod::Dependency.new('monkey', '>= 1')]
@spec.dependencies.should == [Pod::Dependency.new('monkey', '>= 1')]
end
# TODO
......
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