Skip to content

Commit

Permalink
Add symbol getter and setter for dst_subfolder_spec to PBXCopyFilesBu…
Browse files Browse the repository at this point in the history
…ildPhase
  • Loading branch information
mrackwitz committed Oct 25, 2014
1 parent 24fbbf9 commit 4e2bf46
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/xcodeproj/project/object/build_phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,31 @@ class PBXCopyFilesBuildPhase < AbstractBuildPhase
# copied to.
#
attribute :dst_subfolder_spec, String, Constants::COPY_FILES_BUILD_PHASE_DESTINATIONS[:resources]

# Alias method for #dst_subfolder_spec=, which accepts symbol values
# instead of numeric string values.
#
# @param [Symbol] value
# one of `COPY_FILES_BUILD_PHASE_DESTINATIONS.keys`
#
# @raise [StandardError] if value is not a valid known key
#
def symbol_dst_subfolder_spec=(value)
numeric_value = Constants::COPY_FILES_BUILD_PHASE_DESTINATIONS[value]
raise "[Xcodeproj] Value checking error: got `#{value.inspect}` for" \
' attribute: dst_subfolder_spec' if numeric_value.nil?
self.dst_subfolder_spec = numeric_value
end

# Alias method for #dst_subfolder_spec, which returns symbol values
# instead of numeric string values.
#
# @return [Symbol]
#
def symbol_dst_subfolder_spec
key = Constants::COPY_FILES_BUILD_PHASE_DESTINATIONS.find { |_, num| num == dst_subfolder_spec }
key ? key.first : nil
end
end

#-----------------------------------------------------------------------#
Expand Down
22 changes: 22 additions & 0 deletions spec/project/object/build_phase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ module ProjectSpecs
it 'defaults the dstSubfolderSpec to the resources folder' do
@build_phase.dst_subfolder_spec.should == '7'
end

describe '#symbol_dst_subfolder_spec' do
it 'returns the matching value' do
@build_phase.symbol_dst_subfolder_spec.should == :resources
end

it 'returns nil if the key is unknown' do
@build_phase.dst_subfolder_spec = '42'
@build_phase.symbol_dst_subfolder_spec.should.be.nil
end
end

describe '#symbol_dst_subfolder_spec=' do
it 'accepts valid values' do
@build_phase.symbol_dst_subfolder_spec = :frameworks
@build_phase.symbol_dst_subfolder_spec.should == :frameworks
end

it 'raises if an invalid value is set by #symbol_dst_subfolder_spec=' do
lambda { @build_phase.symbol_dst_subfolder_spec = :watch_faces }.should.raise?(StandardError)
end
end
end

describe PBXShellScriptBuildPhase do
Expand Down

0 comments on commit 4e2bf46

Please sign in to comment.