Sha256: 8e0445a39ea499903f619fef6c878a2df9a3ff97c6325803479155ebfb3b4758

Contents?: true

Size: 546 Bytes

Versions: 27

Compression:

Stored size: 546 Bytes

Contents

require 'cgi'

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

  #validations
  validate :document_id_should_exist

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

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

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
classiccms-0.7.5 lib/classiccms/models/slug.rb
classiccms-0.7.4 lib/classiccms/models/slug.rb
classiccms-0.7.3 lib/classiccms/models/slug.rb
classiccms-0.7.2 lib/classiccms/models/slug.rb
classiccms-0.7.1 lib/classiccms/models/slug.rb
classiccms-0.7.0 lib/classiccms/models/slug.rb
classiccms-0.6.9 lib/classiccms/models/slug.rb
classiccms-0.6.8 lib/classiccms/models/slug.rb
classiccms-0.6.7 lib/classiccms/models/slug.rb
classiccms-0.6.6 lib/classiccms/models/slug.rb
classiccms-0.6.5 lib/classiccms/models/slug.rb
classiccms-0.6.4 lib/classiccms/models/slug.rb
classiccms-0.6.3 lib/classiccms/models/slug.rb
classiccms-0.6.2 lib/classiccms/models/slug.rb
classiccms-0.6.1 lib/classiccms/models/slug.rb
classiccms-0.6.0 lib/classiccms/models/slug.rb
classiccms-0.5.17 lib/classiccms/models/slug.rb
classiccms-0.5.16 lib/classiccms/models/slug.rb
classiccms-0.5.15 lib/classiccms/models/slug.rb
classiccms-0.5.14 lib/classiccms/models/slug.rb