module Pod::Specification::JSONSupport
Public Instance Methods
to_hash()
click to toggle source
@return [Hash] the hash representation of the specification including
subspecs.
# File lib/cocoapods-core/specification/json.rb, line 23 def to_hash hash = attributes_hash.dup if root? || available_platforms != parent.available_platforms platforms = Hash[available_platforms.map { |p| [p.name.to_s, p.deployment_target && p.deployment_target.to_s] }] hash['platforms'] = platforms end specs_by_type = subspecs.group_by(&:spec_type) all_appspecs = specs_by_type[:app] || [] all_testspecs = specs_by_type[:test] || [] all_subspecs = specs_by_type[:library] || [] hash.delete('testspecs') hash['testspecs'] = all_testspecs.map(&:to_hash) unless all_testspecs.empty? hash.delete('appspecs') hash['appspecs'] = all_appspecs.map(&:to_hash) unless all_appspecs.empty? hash.delete('subspecs') hash['subspecs'] = all_subspecs.map(&:to_hash) unless all_subspecs.empty? # Since CocoaPods 1.7 version the DSL has changed to be pluralized. When we serialize a podspec to JSON with # 1.7, ensure that we also include the singular version in the hash to maintain backwards compatibility with # < 1.7 versions. We also delete this key and re-add it to ensure it gets added at the end. hash.delete('swift_version') hash['swift_version'] = swift_version.to_s unless swift_version.nil? hash end
to_json(*a)
click to toggle source
@return [String] the json representation of the specification.
# File lib/cocoapods-core/specification/json.rb, line 6 def to_json(*a) require 'json' JSON.dump(to_hash, *a) << "\n" end
to_pretty_json(*a)
click to toggle source
@return [String] the pretty json representation of the specification.
# File lib/cocoapods-core/specification/json.rb, line 13 def to_pretty_json(*a) require 'json' JSON.pretty_generate(to_hash, *a) << "\n" end