Skip to content

Instantly share code, notes, and snippets.

@zudochkin
Created March 5, 2013 10:42
Show Gist options
  • Save zudochkin/5089419 to your computer and use it in GitHub Desktop.
Save zudochkin/5089419 to your computer and use it in GitHub Desktop.
class Article
include DataMapper::Resource
INTERESTING_KEYWORDS = %w(ruby rails coffee javascript ember angular
backbone tdd rspec shoulda gem unicorn nginx sinatra vim mac)
property :id, Serial
property :url, String, :unique_index => :u, :required => true, :format => :url
property :title, String, :required => true, :index => true
property :interesting, Boolean, :default => false
property :read_at, DateTime
timestamps :created_at, :updated_on # Add these only
def interesting?
!!(title =~ Regexp.new(INTERESTING_KEYWORDS.join('|'), Regexp::IGNORECASE))
end
def self.interesting_to_me
all(:interesting => true)
end
def self.unread
all(:read_at => nil)
end
def self.search(term='')
all(:title.like => "%#{term.to_s}%")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment