Created
September 10, 2010 13:57
-
-
Save fjfish/573668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# generate_resource(Story) | |
# This generates the things you need to paste into data access | |
# classes when you're using the objective resource Objective C library | |
# http://iphoneonrails.com | |
# either save and load it or paste into a script/console session | |
def generate_resource(table) | |
cols = table.column_names.select { |c| !["created_at","updated_at"].include?(c)}.collect { |n| n.camelcase(:lower)} | |
theString = "" | |
theString += " // This goes in the curly brackets of the @interface\n" | |
cols.each { |n| theString += " NSString * #{n} ;\n" } | |
theString += "\n // This goes after the curly braces\n" | |
cols.each { |n| theString += " @property (nonatomic , retain) NSString *#{n} ;\n" } | |
theString += "\n // This goes in the .m file\n" | |
theString += " @synthesize " + cols.join(", ") + "\n" | |
puts theString | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment