lib/saasable/mongoid/saas_document.rb in saasable-5.0.2 vs lib/saasable/mongoid/saas_document.rb in saasable-5.0.3

- old
+ new

@@ -16,11 +16,11 @@ # Validations validates_uniqueness_of :hosts # Indexes - index({hosts: 1}) + index({hosts: 1}, unique: true) end klass.instance_variable_set("@_after_activate_chain", []) klass.instance_variable_set("@_after_deactivate_chain", []) end @@ -53,16 +53,14 @@ def find_by_host! a_host if Saasable::Mongoid::SaasDocument.saas_document.nil? raise Saasable::Errors::NoSaasDocuments, "you need to set one Saasable::SaasDocument" end - possible_saas = Saasable::Mongoid::SaasDocument.saas_document.where(hosts: a_host).to_a - if possible_saas.empty? + possible_saas = Saasable::Mongoid::SaasDocument.saas_document.where(hosts: a_host).first + if possible_saas.nil? raise Saasable::Errors::SaasNotFound, "no #{Saasable::Mongoid::SaasDocument.saas_document.name} found for the host: \"#{a_host}\"" - elsif possible_saas.count > 1 - raise Saasable::Errors::MultipleSaasFound, "more then 1 #{Saasable::Mongoid::SaasDocument.saas_document.name} found for the host: \"#{a_host}\"" else - return possible_saas.first + return possible_saas end end def active_saas Thread.current[:saasable_active_saas]