lib/ecoportal/api/common/content/double_model.rb in ecoportal-api-v2-0.8.12 vs lib/ecoportal/api/common/content/double_model.rb in ecoportal-api-v2-0.8.13
- old
+ new
@@ -238,11 +238,11 @@
end
end
inheritable_class_vars :forced_model_keys
-
+
attr_reader :_parent, :_key
def initialize(doc = {}, parent: self, key: nil)
@_dim_vars = []
@_parent = parent || self
@@ -365,12 +365,12 @@
raise UnlinkedModel.new(from: "#{self.class}#replace_doc", key: _key) unless linked?
if is_root?
@doc = new_doc
else
dig_set(_parent.doc, [_doc_key(_key)].flatten, new_doc)
- _parent.variable_remove!(_key)
- variables_remove!
+ _parent.variable_remove!(_key) unless new_doc
+ #variables_remove!
end
end
protected
@@ -383,13 +383,13 @@
end
def replace_original_doc(new_doc)
raise UnlinkedModel.new(from: "#{self.class}#replace_original_doc", key: _key) unless linked?
if is_root?
- @orginal_doc = new_doc
+ @original_doc = new_doc
else
- dig_set(_parent.orginal_doc, [_doc_key(_key)].flatten, new_doc)
+ dig_set(_parent.original_doc, [_doc_key(_key)].flatten, new_doc)
end
end
# Helper to track down persistent variables
def variable_set(key, value)
@@ -407,13 +407,23 @@
end
end
# Removes all the persistent variables
def variables_remove!
+ #puts "going to remove vars: #{@_dim_vars} on #{self.class} (parent: #{identify_parent(self._parent)})"
@_dim_vars.dup.map {|k| variable_remove!(k)}
end
private
+
+ def identify_parent(object)
+ case object
+ when Ecoportal::API::V2::Page::Stage
+ "stage #{object.name}"
+ when Ecoportal::API::V2::Page::Section
+ "section #{object.heading}"
+ end
+ end
def instance_variable_name(key)
self.class.instance_variable_name(key)
end