-
-
Save danielsdeleo/ef28094749f857a5cbb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# unparse into JSON by iterating over the metadata fields in a constant | |
# order. | |
def cookbook_json | |
json_str = "{\n" | |
fields = JSON_FIELDS.map do |field| | |
field_value = send(field) | |
if (field_value.respond_to?(:empty?) && field_value.empty?) | |
field_json_state = nil | |
else | |
field_json_state = JSON::PRETTY_STATE_PROTOTYPE.dup | |
end | |
%Q{ #{field.to_json(nil,1)}: #{field_value.to_json(field_json_state,1)}} | |
end | |
json_str << fields.join(",\n") | |
json_str << "\n}\n" | |
json_str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment