Sha256: 123c80e5e3ede3e5d62d579657c2a6f3c6af4e2d28196f4243ccb7c37c5bcc7c

Contents?: true

Size: 864 Bytes

Versions: 10

Compression:

Stored size: 864 Bytes

Contents

class Article < CouchRest::Model::Base
  use_database DB
  unique_id :slug

  design do
    view :by_date # Default options not supported: :descending => true
    view :by_user_id_and_date

    view :by_tags,
      :map => 
        "function(doc) {
          if (doc['#{model.model_type_key}'] == 'Article' && doc.tags) {
            doc.tags.forEach(function(tag){
              emit(tag, 1);
            });
          }
        }",
      :reduce => 
        "function(keys, values, rereduce) {
          return sum(values);
        }"

  end

  property :date, Date
  property :slug, :read_only => true
  property :user_id
  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

10 entries across 10 versions & 1 rubygems

Version Path
couchrest_model-2.1.0.rc1 spec/fixtures/models/article.rb
couchrest_model-2.1.0.beta2 spec/fixtures/models/article.rb
couchrest_model-2.1.0.beta1 spec/fixtures/models/article.rb
couchrest_model-2.0.4 spec/fixtures/models/article.rb
couchrest_model-2.0.3 spec/fixtures/models/article.rb
couchrest_model-2.0.1 spec/fixtures/models/article.rb
couchrest_model-2.0.0 spec/fixtures/models/article.rb
couchrest_model-2.0.0.beta2 spec/fixtures/models/article.rb
couchrest_model-2.0.0.beta spec/fixtures/models/article.rb
couchrest_model-1.2.0.beta spec/fixtures/models/article.rb