Skip to content

Instantly share code, notes, and snippets.

@manveru
Forked from oren/gist:596353
Created September 25, 2010 02:11
Show Gist options
  • Save manveru/596376 to your computer and use it in GitHub Desktop.
Save manveru/596376 to your computer and use it in GitHub Desktop.
module ProjectReader
module_function
# finds keys in .erb files from a given directory
def find_keys(path)
keys = Dir[File.join(path, '**/*.erb')].map{|path|
extract_keys(path)
}.flatten
unless keys.empty?
if client = Client.find_by_repository_name(File.basename(path))
mark_missing_keys_as_deleted(client)
end
end
end
# extracts keys from a given file and adds to a given array
def extract_keys(path)
File.read(path).scan(/@content\[\'[^']+\'\]/)
end
def mark_missing_keys_as_deleted(client)
TranslationKey.all(:conditions => {:client_id => client}).each do |key|
key.deleted = true
key.save!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment