Skip to content

Instantly share code, notes, and snippets.

@jocap
Created December 6, 2010 18:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jocap/730682 to your computer and use it in GitHub Desktop.
Save jocap/730682 to your computer and use it in GitHub Desktop.
require "dm-core"
require "dm-migrations"
# Configure DataMapper
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://database.db")
# model Article
class Article
include DataMapper::Resource
property :id, Serial
property :title, Text
property :text, Text
property :author, String
property :permalink, Text
property :created_at, DateTime
end
# Update database
DataMapper.auto_upgrade!
class String
# Fix DataMapper's weird space bug
def rm_ln
self.gsub(/\n\n|\n/, "\r")
end
def rm_ln!
self.gsub(/\n\n|\n/, "")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment