lib/jazzy/podspec_documenter.rb in jazzy-0.9.4 vs lib/jazzy/podspec_documenter.rb in jazzy-0.9.5

- old
+ new

@@ -25,11 +25,11 @@ .select { |pt| pt.pod_name == podspec.root.name } .map(&:label) targets.map do |t| args = %W[doc --module-name #{podspec.module_name} -- -target #{t}] - swift_version = (config.swift_version || '4')[0] + '.0' + swift_version = compiler_swift_version(config.swift_version) args << "SWIFT_VERSION=#{swift_version}" SourceKitten.run_sourcekitten(args) end end stdout.reduce([]) { |a, s| a + JSON.parse(s) }.to_json @@ -94,9 +94,26 @@ return unless rev = podspec.source[:tag] || podspec.source[:commit] "https://github.com/#{org}/#{repo}/blob/#{rev}" end private_class_method :github_file_prefix + + # Latest valid value for SWIFT_VERSION. + LATEST_SWIFT_VERSION = '4.2'.freeze + + # All valid values for SWIFT_VERSION that are longer + # than a major version number. Ordered ascending. + LONG_SWIFT_VERSIONS = ['4.2'].freeze + + # Go from a full Swift version like 4.2.1 to + # something valid for SWIFT_VERSION. + def compiler_swift_version(user_version) + return LATEST_SWIFT_VERSION unless user_version + + LONG_SWIFT_VERSIONS.select do |version| + user_version.start_with?(version) + end.last || "#{user_version[0]}.0" + end # @!group SourceKitten output helper methods def pod_path if podspec.defined_in_file