lib/saasable/mongoid/saas_document.rb in saasable-0.3.2 vs lib/saasable/mongoid/saas_document.rb in saasable-0.3.3
- old
+ new
@@ -19,10 +19,11 @@
# Indexes
index :hosts
end
+ klass.instance_variable_set("@_active_saas", nil)
klass.instance_variable_set("@_after_activate_chain", [])
klass.instance_variable_set("@_after_deactivate_chain", [])
end
def self.saas_document
@@ -38,10 +39,11 @@
klass.default_scoping[:where][:saas_id] = self._id
klass.class_eval "field :saas_id, :type => BSON::ObjectId, :default => BSON::ObjectId(\"#{self._id}\")"
end
+ self.class.instance_variable_set("@_active_saas", self)
self.class.instance_variable_get("@_after_activate_chain").each { |method_name| send(method_name) }
end
def deactivate!
self.class.deactivate_all!
@@ -55,11 +57,12 @@
klass.fields["saas_id"].default_val = nil
klass.fields["saas_id"].options.delete(:default)
end
- @_after_deactivate_chain.each { |method_name| send(method_name) }
+ last_active_saas, @_active_saas = active_saas, nil
+ @_after_deactivate_chain.each { |method_name| last_active_saas.send(method_name) }
end
def find_by_host! a_host
if Saasable::Mongoid::SaasDocument.saas_document.nil?
if Rails.env.production?
@@ -77,14 +80,26 @@
else
return possible_saas.first
end
end
- def after_activate method_name
- @_after_activate_chain << method_name
+ def active_saas
+ @_active_saas
end
- def after_deactivate method_name
- @_after_deactivate_chain << method_name
+ def after_activate *method_names
+ @_after_activate_chain += method_names
+ end
+
+ def after_deactivate *method_names
+ @_after_deactivate_chain += method_names
+ end
+
+ def remove_after_activate *method_names
+ @_after_activate_chain -= method_names
+ end
+
+ def remove_after_deactivate *method_names
+ @_after_deactivate_chain -= method_names
end
end
end
\ No newline at end of file