Sha256: 043e42bdd770609144e9f78696a70a40e0a471e82f3031cc495281ce4bdc9b5d

Contents?: true

Size: 553 Bytes

Versions: 19

Compression:

Stored size: 553 Bytes

Contents

require 'cgi'

class Slug
	include Mongoid::Document
  identity :type => String
	field :document_id, type: BSON::ObjectId

  #validations
  validate :document_id_should_exist

  def document_id_should_exist
    if !Base.exists?(conditions: {id: document_id})
      errors.add :document_id, "id doesn't exist"
    end
  end

  def generate_id
    i = 0
    i+=1 while Slug.exists? conditions: {id: i.to_s}
    self.id = i.to_s
  end
  def set_id(url)
    Slug.where(id: url).delete_all
    self.id = url.gsub(/[^a-zA-Z0-9\-\/]+/, '-').downcase
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
classiccms-0.5.6 lib/classiccms/models/slug.rb
classiccms-0.5.5 lib/classiccms/models/slug.rb
classiccms-0.5.2 lib/classiccms/models/slug.rb
classiccms-0.5.1 lib/classiccms/models/slug.rb
classiccms-0.5.0 lib/classiccms/models/slug.rb
classiccms-0.4.2 lib/classiccms/models/slug.rb
classiccms-0.4.1 lib/classiccms/models/slug.rb
classiccms-0.4.0 lib/classiccms/models/slug.rb
classiccms-0.3.9 lib/classiccms/models/slug.rb
classiccms-0.3.8 lib/classiccms/models/slug.rb
classiccms-0.3.7 lib/classiccms/models/slug.rb
classiccms-0.3.6 lib/classiccms/models/slug.rb
classiccms-0.3.5 lib/classiccms/models/slug.rb
classiccms-0.3.4 lib/classiccms/models/slug.rb
classiccms-0.3.3 lib/classiccms/models/slug.rb
classiccms-0.3.2 lib/classiccms/models/slug.rb
classiccms-0.3.1 lib/classiccms/models/slug.rb
classiccms-0.3.0 lib/classiccms/models/slug.rb
classiccms-0.2.4.pre lib/classiccms/models/slug.rb