Skip to content

Instantly share code, notes, and snippets.

@tadast
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadast/97016c420f83c13e7e99 to your computer and use it in GitHub Desktop.
Save tadast/97016c420f83c13e7e99 to your computer and use it in GitHub Desktop.
Unused YAML keys
def find_keys(hash)
hash.flat_map do |key, value|
if value.is_a?(Hash)
find_keys(value)
else
key
end
end
end
phrases = YAML.load_file("lib/smart_answer_flows/locales/en/marriage-abroad.yml")
keys = find_keys(phrases).uniq
logic_file = File.open("lib/smart_answer_flows/marriage-abroad.rb", "r").read
test_file = File.open("test/integration/smart_answer_flows/marriage_abroad_test.rb", "r").read
unused = keys.select do |key|
logic_file.exclude?(key) && test_file.exclude?(key)
end - %w(description hint)
puts "Potentially unused keys (they may be coming from interpolated strings in the logic file):"
puts unused
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment