Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactoring and adding types

  • Loading branch information...
commit b8e6a068af52f0d9f1db2dac6066204f776eee05 1 parent 713fd32
Christopher Burnett authored
29 generators/objectify/objectify_generator.rb
... ... @@ -1,4 +1,33 @@
  1 +POINTER_TYPES = {
  2 + :datetime => "NSDate",
  3 + :date => "NSDate",
  4 + :string => "NSString",
  5 + :text => "NSString",
  6 + :integer => "NSNumber",
  7 + :float => "NSDecimalNumber",
  8 + :double => "NSDecimalNumber"
  9 + }
1 10 class ObjectifyGenerator < Rails::Generator::NamedBase
  11 +
  12 + def objc_type type
  13 + POINTER_TYPES[type]
  14 + end
  15 +
  16 + def synthesize_cols mdl
  17 + file_name.camelize.constantize.columns.inject("") do |str,col|
  18 + unless col.name == "id"
  19 + str << "#{col.name.camelize(:lower)}"
  20 + else
  21 + str << "#{file_name.camelize(:lower)}Id"
  22 + end
  23 + unless col == file_name.camelize.constantize.columns.last
  24 + str << ", "
  25 + else
  26 + str << ";"
  27 + end
  28 + end
  29 + end
  30 +
2 31
3 32 def manifest
4 33 if file_name.camelize.constantize
22 generators/objectify/templates/model.h
... ... @@ -1,29 +1,11 @@
1 1 #import "ObjectiveResource.h"
2   -<%-
3   -def objc_type type
4   - case
5   - when type.match(/^int/)
6   - "NSNumber"
7   - when type.match(/varchar/)
8   - "NSString"
9   - when type.match(/tinyint/)
10   - "NSString"
11   - when type.match(/text/)
12   - "NSString"
13   - when type.match(/date/)
14   - "NSDate"
15   - else
16   - "NSString"
17   - end
18   -end
19   --%>
20 2
21 3 @interface <%= file_name.camelize %> : NSObject {
22 4 <%- file_name.camelize.constantize.columns.each do |col| -%>
23 5 <%- unless col.name == "id" -%>
24   - <%=objc_type col.sql_type%> *<%= col.name.camelize(:lower) -%>;
  6 + <%=objc_type col.type%> *<%= col.name.camelize(:lower) -%>;
25 7 <%- else -%>
26   - NSString *<%= file_name.camelize(:lower) -%>Id;
  8 + <%=objc_type col.type%> *<%= file_name.camelize(:lower) -%>Id;
27 9 <%- end -%>
28 10 <% end %>
29 11 }
17 generators/objectify/templates/model.m
... ... @@ -1,22 +1,9 @@
1 1 #import "<%=file_name.camelize%>.h"
2 2 <%-
3   -def do_synth mdl
4   - file_name.camelize.constantize.columns.inject("") do |str,col|
5   - unless col.name == "id"
6   - str << "#{col.name.camelize(:lower)}"
7   - else
8   - str << "#{file_name.camelize(:lower)}Id"
9   - end
10   - unless col == file_name.camelize.constantize.columns.last
11   - str << ", "
12   - else
13   - str << ";"
14   - end
15   - end
16   -end
  3 +
17 4 -%>
18 5 @implementation <%=file_name.camelize%>
19   -@synthesize <%=do_synth file_name%>
  6 +@synthesize <%= synthesize_cols file_name%>
20 7
21 8 + (NSString *)getRemoteCollectionName {
22 9 return @"<%=file_name.pluralize%>";

0 comments on commit b8e6a06

Please sign in to comment.
Something went wrong with that request. Please try again.