Permalink
Browse files

Refactoring and adding types

  • Loading branch information...
1 parent 713fd32 commit b8e6a068af52f0d9f1db2dac6066204f776eee05 @twoism committed Mar 7, 2009
View
29 generators/objectify/objectify_generator.rb
@@ -1,4 +1,33 @@
+POINTER_TYPES = {
+ :datetime => "NSDate",
+ :date => "NSDate",
+ :string => "NSString",
+ :text => "NSString",
+ :integer => "NSNumber",
+ :float => "NSDecimalNumber",
+ :double => "NSDecimalNumber"
+ }
class ObjectifyGenerator < Rails::Generator::NamedBase
+
+ def objc_type type
+ POINTER_TYPES[type]
+ end
+
+ def synthesize_cols mdl
+ file_name.camelize.constantize.columns.inject("") do |str,col|
+ unless col.name == "id"
+ str << "#{col.name.camelize(:lower)}"
+ else
+ str << "#{file_name.camelize(:lower)}Id"
+ end
+ unless col == file_name.camelize.constantize.columns.last
+ str << ", "
+ else
+ str << ";"
+ end
+ end
+ end
+
def manifest
if file_name.camelize.constantize
View
22 generators/objectify/templates/model.h
@@ -1,29 +1,11 @@
#import "ObjectiveResource.h"
-<%-
-def objc_type type
- case
- when type.match(/^int/)
- "NSNumber"
- when type.match(/varchar/)
- "NSString"
- when type.match(/tinyint/)
- "NSString"
- when type.match(/text/)
- "NSString"
- when type.match(/date/)
- "NSDate"
- else
- "NSString"
- end
-end
--%>
@interface <%= file_name.camelize %> : NSObject {
<%- file_name.camelize.constantize.columns.each do |col| -%>
<%- unless col.name == "id" -%>
- <%=objc_type col.sql_type%> *<%= col.name.camelize(:lower) -%>;
+ <%=objc_type col.type%> *<%= col.name.camelize(:lower) -%>;
<%- else -%>
- NSString *<%= file_name.camelize(:lower) -%>Id;
+ <%=objc_type col.type%> *<%= file_name.camelize(:lower) -%>Id;
<%- end -%>
<% end %>
}
View
17 generators/objectify/templates/model.m
@@ -1,22 +1,9 @@
#import "<%=file_name.camelize%>.h"
<%-
-def do_synth mdl
- file_name.camelize.constantize.columns.inject("") do |str,col|
- unless col.name == "id"
- str << "#{col.name.camelize(:lower)}"
- else
- str << "#{file_name.camelize(:lower)}Id"
- end
- unless col == file_name.camelize.constantize.columns.last
- str << ", "
- else
- str << ";"
- end
- end
-end
+
-%>
@implementation <%=file_name.camelize%>
-@synthesize <%=do_synth file_name%>
+@synthesize <%= synthesize_cols file_name%>
+ (NSString *)getRemoteCollectionName {
return @"<%=file_name.pluralize%>";

0 comments on commit b8e6a06

Please sign in to comment.