lib/saasable/mongoid/scoped_document.rb in saasable-4.0.2 vs lib/saasable/mongoid/scoped_document.rb in saasable-5.0.0

- old
+ new

@@ -1,30 +1,25 @@ 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 # Fields - field :saas_id, :type => BSON::ObjectId + field :saas_id, type: BSON::ObjectId, default: ->{ Saasable::Mongoid::SaasDocument.active_saas } + # Default scope + default_scope ->{ Saasable::Mongoid::SaasDocument.active_saas ? where(saas_id: Saasable::Mongoid::SaasDocument.active_saas) : all } + # Indexes index({saas_id: 1}) index({saad_id: 1, _id: 1}) class << self alias_method_chain :index, :saasable end end end - def self.scoped_documents - @scoped_documents - end - def saas= a_saas self.saas_id = a_saas._id end def saas @@ -38,10 +33,10 @@ attributes[:scope] << :saas_id unless attributes[:scope].include?(:saas_id) validates_with(Mongoid::Validatable::UniquenessValidator, attributes) end - def index_with_saasable(spec, options = nil) + def index_with_saasable(spec, options = {}) index_without_saasable(spec, options.merge({unique: false})) index_without_saasable({saas_id: 1}.merge(spec), options) unless spec.include?(:saas_id) end end end