diff --git a/ProcessHeader.rb b/ProcessHeader.rb new file mode 100644 index 0000000..c30ba90 --- /dev/null +++ b/ProcessHeader.rb @@ -0,0 +1,94 @@ +# +# ProcessHeader.rb +# Magical Record +# +# Created by Saul Mora on 11/14/11. +# Copyright 2011 Magical Panda Software LLC. All rights reserved. +# + + +def processHeader(headerFile) + unless headerFile.end_with? ".h" + puts "#{headerFile} not a header" + return + end + + puts "Reading #{headerFile}" + + method_match_expression = /^(?[\+|\-]\s*\([a-zA-Z\s\*]*\)\s*)(?\w+)(?\:?.*)/ + category_match_expression = /^\s*(?@[[:alnum:]]+)\s*(?[[:alnum:]]+)\s*(\((?\w+)\))?/ + + lines = File.readlines(headerFile) + non_prefixed_methods = [] + processed_methods_count = 0 + + lines.each { |line| + + processed_line = nil + if line.start_with?("@interface") + matches = category_match_expression.match(line) + processed_line = "#{matches[:Interface]} #{matches[:ObjectName]} (#{matches[:Category]}ShortHand)" + end + + if processed_line == nil + matches = method_match_expression.match(line) + + if matches + if matches[:MethodName].start_with?("MR_") + ++processed_methods_count + methodName = matches[:MethodName].sub("MR_", "") + processed_line = "#{matches[:Start]}#{methodName}#{matches[:End]}" + + else + non_prefixed_methods = nil + return + end + end + end + + if processed_line == nil + if line.start_with?("@end") + processed_line = "@end" + end + end + + unless processed_line == nil + # puts "#{line} -----> #{processed_line}" + non_prefixed_methods << processed_line + end + } + + non_prefixed_methods #unless processed_methods_count == 0 +end + +def processDirectory(path) + + headers = File.join(path, "**", "*+*.h") + Dir.glob(headers).each { |file| +# puts "Processing #{file}" + + processDirectory(file) if File.directory?(file) + if file.end_with?(".h") + processedInterface = processHeader(file) + + puts processedInterface + end + } + +end + +if ARGV[0] + path = "#{Dir.pwd}/#{ARGV[0]}" + + if path.end_with?(".h") + processedInterface = processHeader(path) + + puts processedInterface + + else + processDirectory(path) + end + +else + processDirectory(ARGV[0] || Dir.getwd()) +end diff --git a/Source/Categories/NSManagedObject+MagicalDataImport.h b/Source/Categories/NSManagedObject+MagicalDataImport.h index d9ec55c..f08ee2a 100644 --- a/Source/Categories/NSManagedObject+MagicalDataImport.h +++ b/Source/Categories/NSManagedObject+MagicalDataImport.h @@ -32,23 +32,3 @@ extern NSString * const kMagicalRecordImportRelationshipTypeKey; + (id) MR_updateFromDictionary:(NSDictionary *)objectData inContext:(NSManagedObjectContext *)context; @end - - -#ifdef MR_SHORTHAND - -@interface NSManagedObject (NSManagedObject_DataImport_ShortHand) - -- (void) importValuesForKeysWithDictionary:(NSDictionary *)objectData; -- (void) updateValuesForKeysWithDictionary:(NSDictionary *)objectData; - -+ (id) importFromDictionary:(NSDictionary *)data; -+ (id) importFromDictionary:(NSDictionary *)data inContext:(NSManagedObjectContext *)context; - -+ (NSArray *) importFromArray:(NSArray *)listOfObjectData; -+ (NSArray *) importFromArray:(NSArray *)listOfObjectData inContext:(NSManagedObjectContext *)context; - -+ (id) updateFromDictionary:(NSDictionary *)objectData; -+ (id) updateFromDictionary:(NSDictionary *)objectData inContext:(NSManagedObjectContext *)context; - -@end -#endif \ No newline at end of file