Commit 441eac88 authored by Eloy Duran's avatar Eloy Duran

Return a groups children as an object list.

parent 4b20d585
...@@ -16,9 +16,9 @@ module Pod ...@@ -16,9 +16,9 @@ module Pod
names.each { |name| attribute(name) } names.each { |name| attribute(name) }
end end
def self.has_many(plural_attr_name, options) def self.has_many(plural_attr_name, options = {})
klass = options[:class] klass = options[:class] || PBXFileReference
singular_attr_name = plural_attr_name.to_s[0..-2] # strip off 's' singular_attr_name = options[:singular] || plural_attr_name.to_s[0..-2] # strip off 's'
uuid_list_name = "#{singular_attr_name}References" uuid_list_name = "#{singular_attr_name}References"
attribute(plural_attr_name, uuid_list_name) attribute(plural_attr_name, uuid_list_name)
define_method(plural_attr_name) do define_method(plural_attr_name) do
...@@ -80,25 +80,48 @@ module Pod ...@@ -80,25 +80,48 @@ module Pod
end end
end end
class PBXGroup < PBXObject class PBXFileReference < PBXObject
attributes :sourceTree, :children attributes :path, :sourceTree
def initialize(project, uuid, attributes) def initialize(project, uuid, attributes)
is_new = uuid.nil?
super
self.name ||= pathname.basename.to_s
self.sourceTree ||= 'SOURCE_ROOT'
if is_new
@project.build_files.new.file = self
end
end
def pathname
Pathname.new(path)
end
def build_file
@project.build_files.find { |o| o.fileRef == uuid }
end
end
class PBXGroup < PBXObject
attributes :sourceTree
has_many :children, :singular => :child
def initialize(*)
super super
self.sourceTree ||= '<group>' self.sourceTree ||= '<group>'
self.children ||= [] self.childReferences ||= []
end end
def files def files
list_by_class(children, PBXFileReference) list_by_class(childReferences, PBXFileReference)
end end
def source_files def source_files
list_by_class(children, PBXFileReference, files.select { |file| !file.build_file.nil? }) list_by_class(childReferences, PBXFileReference, files.select { |file| !file.build_file.nil? })
end end
def groups def groups
list_by_class(children, PBXGroup) list_by_class(childReferences, PBXGroup)
end end
def add_source_file(path, copy_header_phase = nil, compiler_flags = nil) def add_source_file(path, copy_header_phase = nil, compiler_flags = nil)
...@@ -119,29 +142,7 @@ module Pod ...@@ -119,29 +142,7 @@ module Pod
end end
def <<(child) def <<(child)
children << child.uuid childReferences << child.uuid
end
end
class PBXFileReference < PBXObject
attributes :path, :sourceTree
def initialize(project, uuid, attributes)
is_new = uuid.nil?
super
self.name ||= pathname.basename.to_s
self.sourceTree ||= 'SOURCE_ROOT'
if is_new
@project.build_files.new.file = self
end
end
def pathname
Pathname.new(path)
end
def build_file
@project.build_files.find { |o| o.fileRef == uuid }
end end
end end
......
...@@ -220,7 +220,7 @@ describe "Pod::Xcode::Project" do ...@@ -220,7 +220,7 @@ describe "Pod::Xcode::Project" do
it "adds a group to the `Pods' group" do it "adds a group to the `Pods' group" do
group = @project.add_pod_group('JSONKit') group = @project.add_pod_group('JSONKit')
@project.pods.children.should.include group.uuid @project.pods.childReferences.should.include group.uuid
find_object({ find_object({
'isa' => 'PBXGroup', 'isa' => 'PBXGroup',
'name' => 'JSONKit', 'name' => 'JSONKit',
...@@ -251,7 +251,7 @@ describe "Pod::Xcode::Project" do ...@@ -251,7 +251,7 @@ describe "Pod::Xcode::Project" do
}) })
build_file_uuids << build_file_uuid build_file_uuids << build_file_uuid
group.children.should == file_ref_uuids group.childReferences.should == file_ref_uuids
_, object = find_object('isa' => 'PBXSourcesBuildPhase') _, object = find_object('isa' => 'PBXSourcesBuildPhase')
object['files'].should == build_file_uuids object['files'].should == build_file_uuids
......
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