Skip to content

Commit

Permalink
CocoaPods#630 : filerefs now take parent group location into account
Browse files Browse the repository at this point in the history
  • Loading branch information
kingfai committed Dec 14, 2018
1 parent dd1e038 commit af725ec
Show file tree
Hide file tree
Showing 18 changed files with 855 additions and 12 deletions.
13 changes: 13 additions & 0 deletions lib/xcodeproj/workspace/file_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,22 @@ def hash
#
def self.from_node(xml_node)
type, path = xml_node.attribute('location').value.split(':', 2)
path = prepend_parent_path(xml_node, path)
new(path, type)
end

def self.prepend_parent_path(xml_node, path)
if !xml_node.parent.nil? && (xml_node.parent.name == 'Group')
group = GroupReference.from_node(xml_node.parent)
if !group.location.nil? && !group.location.empty?
path = '' if path.nil?
path = File.join(group.location, path)
end
end

path
end

# @return [REXML::Element] the XML representation of the file reference.
#
def to_node
Expand Down
18 changes: 12 additions & 6 deletions lib/xcodeproj/workspace/group_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@ class GroupReference
#
attr_reader :type

# @return [String] the location of the group on disk
attr_reader :location

# @param [#to_s] name @see name
# @param [#to_s] type @see type
#
def initialize(name, type = 'container')
def initialize(name, type = 'container', location = '')
@name = name.to_s
@type = type.to_s
@location = location.to_s
end

# @return [Bool] Whether a group reference is equal to another.
#
def ==(other)
name == other.name && type == other.type
name == other.name && type == other.type && location == other.location
end
alias_method :eql?, :==

# @return [Fixnum] A hash identical for equals objects.
#
def hash
[name, type].hash
[name, type, location].hash
end

# Returns a group reference given XML representation.
Expand All @@ -46,16 +50,18 @@ def hash
# @return [GroupReference] The new group reference instance.
#
def self.from_node(xml_node)
type = xml_node.attribute('location').value.split(':', 2).first
location_array = xml_node.attribute('location').value.split(':', 2)
type = location_array.first
location = (location_array.length > 1) ? location_array[1] : ''
name = xml_node.attribute('name').value
new(name, type)
new(name, type, location)
end

# @return [REXML::Element] the XML representation of the group reference.
#
def to_node
REXML::Element.new('Group').tap do |element|
element.add_attribute('location', "#{type}:")
element.add_attribute('location', "#{type}:#{location}")
element.add_attribute('name', "#{name}")
end
end
Expand Down
Loading

0 comments on commit af725ec

Please sign in to comment.