Skip to content

Instantly share code, notes, and snippets.

@fjfish
Created September 10, 2010 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjfish/573668 to your computer and use it in GitHub Desktop.
Save fjfish/573668 to your computer and use it in GitHub Desktop.
# 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