Skip to content

Commit

Permalink
[Config] Sort by setting name when serliazing to a string.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Jan 13, 2013
1 parent 954b782 commit 5c24893
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Rakefile
Expand Up @@ -209,6 +209,11 @@ task :dump_xcodeproj => 'ext:cleanbuild' do
puts result.to_yaml
end

desc 'Install dependencies'
task :bootstrap do
sh 'bundle install'
end

desc "Run all specs"
task :spec => 'spec:all'

Expand Down
7 changes: 4 additions & 3 deletions lib/xcodeproj/config.rb
Expand Up @@ -47,16 +47,17 @@ def initialize(xcconfig_hash_or_file = {})

# @!group Serialization

# Serializes the internal data in the xcconfig format.
# Sorts the internal data by setting name and serializes it in the xcconfig
# format.
#
# @example
#
# config = Config.new('PODS_ROOT' => '"$(SRCROOT)/Pods"', 'OTHER_LDFLAGS' => '-lxml2')
# config.to_s # => "PODS_ROOT = \"$(SRCROOT)/Pods\"\nOTHER_LDFLAGS = -lxml2"
# config.to_s # => "OTHER_LDFLAGS = -lxml2\nPODS_ROOT = \"$(SRCROOT)/Pods\""
#
# @return [String] The serialized internal data.
def to_s
to_hash.map { |key, value| "#{key} = #{value}" }.join("\n")
to_hash.sort_by(&:first).map { |k, v| "#{k} = #{v}" }.join("\n")
end

# @return [void] Writes the serialized representation of the internal data
Expand Down
5 changes: 5 additions & 0 deletions spec/config_spec.rb
Expand Up @@ -50,6 +50,11 @@
@config.to_s.should.be.equal "OTHER_LDFLAGS = -framework Foundation"
end

it "sorts the internal data by setting name when serializing with #to_s" do
config = Xcodeproj::Config.new('Y' => '2', 'Z' => '3', 'X' => '1')
config.to_s.should == "X = 1\nY = 2\nZ = 3"
end

it "can be serialized with #to_hash" do
@config.to_hash.should.be.equal @hash
end
Expand Down

0 comments on commit 5c24893

Please sign in to comment.