module Ecoportal module API module Common class BaseModel attr_reader :initial_doc def initialize(doc = {}, parent: self, key: nil) @_parent = parent @_key = key if !_parent || !_key @doc = doc @original_doc = JSON.parse(@doc.to_json) @initial_doc = JSON.parse(@doc.to_json) end end def initial_doc raise UnlinkedModel.new unless linked? return @initial_doc if is_root? _parent.initial_doc.dig(*[_key].flatten) end end end end end