mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-05-04 09:31:55 +08:00
Shorthand header script generator
This commit is contained in:
94
ProcessHeader.rb
Normal file
94
ProcessHeader.rb
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user