Sha256: 67fc7c2500face93ca359a9ced5d4b31b801dab1c91555a3525b39f268e1fdb3

Contents?: true

Size: 752 Bytes

Versions: 8

Compression:

Stored size: 752 Bytes

Contents

class Article < CouchRest::ExtendedDocument
  use_database DB
  unique_id :slug
  
  view_by :date, :descending => true
  view_by :user_id, :date
    
  view_by :tags,
    :map => 
      "function(doc) {
        if (doc['couchrest-type'] == 'Article' && doc.tags) {
          doc.tags.forEach(function(tag){
            emit(tag, 1);
          });
        }
      }",
    :reduce => 
      "function(keys, values, rereduce) {
        return sum(values);
      }"  

  property :date
  property :slug, :read_only => true
  property :title
  property :tags

  timestamps!
  
  before_save :generate_slug_from_title
  
  def generate_slug_from_title
    self['slug'] = title.downcase.gsub(/[^a-z0-9]/,'-').squeeze('-').gsub(/^\-|\-$/,'') if new?
  end
end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
mattetti-couchrest-0.34 spec/fixtures/more/article.rb
norr-couchrest-0.33.06 spec/fixtures/more/article.rb
norr-couchrest-0.33.07 spec/fixtures/more/article.rb
peterpunk-couchrest-0.34.1 spec/fixtures/more/article.rb
sporkd-couchrest-0.30 spec/fixtures/more/article.rb
sporkd-couchrest-0.31 spec/fixtures/more/article.rb
sporkd-couchrest-0.33 spec/fixtures/more/article.rb
sporkd-couchrest-0.34 spec/fixtures/more/article.rb