Sha256: 5fc709bbe6341b53978112d618337bf6d7c732534b05aa7d88008bf3ee02bea0

Contents?: true

Size: 870 Bytes

Versions: 5

Compression:

Stored size: 870 Bytes

Contents

class Article < CouchRest::Model::Base
  use_database DB
  unique_id :slug
  
  provides_collection :article_details, 'Article', 'by_date', :descending => true, :include_docs => true
  view_by :date, :descending => true
  view_by :user_id, :date
    
  view_by :tags,
    :map => 
      "function(doc) {
        if (doc['#{model_type_key}'] == 'Article' && doc.tags) {
          doc.tags.forEach(function(tag){
            emit(tag, 1);
          });
        }
      }",
    :reduce => 
      "function(keys, values, rereduce) {
        return sum(values);
      }"

  property :date, Date
  property :slug, :read_only => true
  property :title
  property :tags, [String]

  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

5 entries across 5 versions & 1 rubygems

Version Path
couchrest_model-1.1.0.beta5 spec/fixtures/more/article.rb
couchrest_model-1.1.0.beta4 spec/fixtures/more/article.rb
couchrest_model-1.1.0.beta3 spec/fixtures/more/article.rb
couchrest_model-1.1.0.beta2 spec/fixtures/more/article.rb
couchrest_model-1.1.0.beta spec/fixtures/more/article.rb