formula: reorder to_hash.

Let's reorder this to more closely match the ordering in a formula file.
This makes `to_hash` (and our JSON output) more useful and easily
readable for people used to formula files.
This commit is contained in:
Mike McQuaid 2018-05-12 10:42:07 -04:00
parent 4ebccf79a8
commit 0797a3e19e

View File

@ -1548,44 +1548,34 @@ class Formula
hsh = { hsh = {
"name" => name, "name" => name,
"full_name" => full_name, "full_name" => full_name,
"desc" => desc,
"homepage" => homepage,
"oldname" => oldname, "oldname" => oldname,
"aliases" => aliases.sort, "aliases" => aliases.sort,
"desc" => desc,
"homepage" => homepage,
"versions" => { "versions" => {
"stable" => stable&.version&.to_s, "stable" => stable&.version&.to_s,
"bottle" => !bottle_specification.checksums.empty?,
"devel" => devel&.version&.to_s, "devel" => devel&.version&.to_s,
"head" => head&.version&.to_s, "head" => head&.version&.to_s,
"bottle" => !bottle_specification.checksums.empty?,
}, },
"revision" => revision, "revision" => revision,
"version_scheme" => version_scheme, "version_scheme" => version_scheme,
"bottle" => {},
"keg_only" => keg_only?,
"options" => [],
"build_dependencies" => dependencies.select(&:build?).map(&:name).uniq,
"dependencies" => dependencies.map(&:name).uniq,
"recommended_dependencies" => dependencies.select(&:recommended?).map(&:name).uniq,
"optional_dependencies" => dependencies.select(&:optional?).map(&:name).uniq,
"requirements" => [],
"conflicts_with" => conflicts.map(&:name),
"caveats" => caveats,
"installed" => [], "installed" => [],
"linked_keg" => linked_version&.to_s, "linked_keg" => linked_version&.to_s,
"pinned" => pinned?, "pinned" => pinned?,
"outdated" => outdated?, "outdated" => outdated?,
"keg_only" => keg_only?,
"dependencies" => dependencies.map(&:name).uniq,
"recommended_dependencies" => dependencies.select(&:recommended?).map(&:name).uniq,
"optional_dependencies" => dependencies.select(&:optional?).map(&:name).uniq,
"build_dependencies" => dependencies.select(&:build?).map(&:name).uniq,
"conflicts_with" => conflicts.map(&:name),
"caveats" => caveats,
} }
hsh["requirements"] = requirements.map do |req|
{
"name" => req.name,
"cask" => req.cask,
"download" => req.download,
}
end
hsh["options"] = options.map do |opt|
{ "option" => opt.flag, "description" => opt.description }
end
hsh["bottle"] = {}
%w[stable devel].each do |spec_sym| %w[stable devel].each do |spec_sym|
next unless spec = send(spec_sym) next unless spec = send(spec_sym)
next unless spec.bottle_defined? next unless spec.bottle_defined?
@ -1607,6 +1597,18 @@ class Formula
hsh["bottle"][spec_sym] = bottle_info hsh["bottle"][spec_sym] = bottle_info
end end
hsh["options"] = options.map do |opt|
{ "option" => opt.flag, "description" => opt.description }
end
hsh["requirements"] = requirements.map do |req|
{
"name" => req.name,
"cask" => req.cask,
"download" => req.download,
}
end
installed_kegs.each do |keg| installed_kegs.each do |keg|
tab = Tab.for_keg keg tab = Tab.for_keg keg