Module: Ecoportal::API::Common::Content::DoubleModel::DoubleDoc::LinkableDoc

Extended by:
Includer
Defined in:
lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb

Defined Under Namespace

Classes: UnlinkedModel

Instance Method Summary collapse

Methods included from Includer

include_missing

Instance Method Details

#as_jsonObject



33
34
35
# File 'lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb', line 33

def as_json
  doc
end

#docnil, Hash

Returns the underlying Hash model as is (carrying current changes).

Returns:

  • (nil, Hash)

    the underlying Hash model as is (carrying current changes)



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb', line 43

def doc
  return @doc if doc_var?
  return @doc if root?

  unless linked?
    raise UnlinkedModel.new(
      from: "#{self.class}##{__method__}",
      key:  _parent_key
    )
  end

  _parent.doc.dig(*resolved_rooted_doc_key)
end

#original_docnil, Hash

The original_doc holds the model as is now on server-side.

Returns:

  • (nil, Hash)

    the underlying Hash model as after last consolidate! changes



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb', line 59

def original_doc
  return @original_doc if root?

  unless linked?
    raise UnlinkedModel.new(
      from: "#{self.class}##{__method__}",
      key:  _parent_key
    )
  end

  _parent.original_doc.dig(*resolved_rooted_doc_key)
end


37
38
39
40
# File 'lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb', line 37

def print_pretty
  puts JSON.pretty_generate(as_json)
  self
end

#to_json(*args) ⇒ Object

INSTANCE METHODS



29
30
31
# File 'lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb', line 29

def to_json(*args)
  doc.to_json(*args)
end