Created
March 5, 2013 10:42
-
-
Save zudochkin/5089419 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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