Skip to content

Commit

Permalink
adding getter and setter for saas in the scoped document
Browse files Browse the repository at this point in the history
  • Loading branch information
cerebroso committed Mar 1, 2012
1 parent c0bfb9a commit 4e03a3e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/saasable/mongoid/scoped_document.rb
@@ -1,26 +1,34 @@
module Saasable::Mongoid::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


def saas= a_saas
self.saas_id = a_saas._id
end

def saas
@saas ||= Saasable::Mongoid::SaasDocument.saas_document.find(self.saas_id)
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
end

0 comments on commit 4e03a3e

Please sign in to comment.