Shorthand header script generator

This commit is contained in:
Saul Mora
2011-11-15 09:48:11 -07:00
parent 068e1242ab
commit e5439914b3
2 changed files with 94 additions and 20 deletions

94
ProcessHeader.rb Normal file
View File

@@ -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 = /^(?<Start>[\+|\-]\s*\([a-zA-Z\s\*]*\)\s*)(?<MethodName>\w+)(?<End>\:?.*)/
category_match_expression = /^\s*(?<Interface>@[[:alnum:]]+)\s*(?<ObjectName>[[:alnum:]]+)\s*(\((?<Category>\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

View File

@@ -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