Skip to content

Instantly share code, notes, and snippets.

@sj26
Last active December 12, 2015 01:58
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 sj26/4695129 to your computer and use it in GitHub Desktop.
Save sj26/4695129 to your computer and use it in GitHub Desktop.
YAML symbol grep
find . -iname "*.gem" | while read file; do
file=$(basename $file)
mkdir -p ../metadata/${file:0:1}/${file:1:1}
tar -xOf ./$file metadata.gz | gunzip -c > ../metadata/${file:0:1}/${file:1:1}/$file:r.metadata ||
tar -xOf ./$file metadata > ../metadata/${file:0:1}/${file:1:1}/$file:r.metadata &&
echo ${file:0:1}/${file:1:1}/$file:r.metadata
done
require 'psych'
# Already extracted metadata from all gems into g/e/gem-1.0.0.metadata style paths.
Dir.glob("?/?/*.metadata") do |file|
begin
Psych.parse_file(file).each do |node|
if node.tag =~ %r{\A!ruby/sym(bol)?(\:.*)?\Z} or (node.is_a? Psych::Nodes::Scalar and node.tag.nil? and not node.quoted and node.value and node.value[/\A:/])
puts "#{file}: #{node.value}"
end
end
rescue Psych::SyntaxError
$stderr.write "#{file}: Syntax Error: #{$!}\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment