-
-
Save manveru/596376 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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