Sha256: ea58191822deadef901e780c0038319007ac95820f6b34f038565bc31263412f

Contents?: true

Size: 656 Bytes

Versions: 3

Compression:

Stored size: 656 Bytes

Contents

module Saasable::ScopedDocument
  @scoped_documents = []
  
  def self.included klass
    @scoped_documents << klass unless @scoped_documents.include? klass
    
    klass.extend ClassMethods
    klass.class_eval do
      field :saas_id, :type => BSON::ObjectId
    end
  end
  
  def self.scoped_documents
    @scoped_documents
  end
  
  module ClassMethods
    def validates_uniqueness_of(*args)
      attributes = _merge_attributes(args)
      attributes[:scope] ||= []
      attributes[:scope] << :saas_id unless attributes[:scope].include?(:saas_id)
      
      validates_with(Mongoid::Validations::UniquenessValidator, attributes)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
saasable-0.1.6 lib/saasable/scoped_document.rb
saasable-0.1.5 lib/saasable/scoped_document.rb
saasable-0.1.4 lib/saasable/scoped_document.rb