Class: Ecoportal::API::Common::Content::DoubleModel

Inherits:
BaseModel
  • Object
show all
Includes:
Attributable, Base, Diffable, DoubleDoc, HashHelpers, Modifiers, Parented, VarTracking
Defined in:
lib/ecoportal/api/common/content/double_model.rb,
lib/ecoportal/api/common/content/double_model/base.rb,
lib/ecoportal/api/common/content/double_model/diffable.rb,
lib/ecoportal/api/common/content/double_model/parented.rb,
lib/ecoportal/api/common/content/double_model/modifiers.rb,
lib/ecoportal/api/common/content/double_model/double_doc.rb,
lib/ecoportal/api/common/content/double_model/attributable.rb,
lib/ecoportal/api/common/content/double_model/hash_helpers.rb,
lib/ecoportal/api/common/content/double_model/var_tracking.rb,
lib/ecoportal/api/common/content/double_model/double_doc/base.rb,
lib/ecoportal/api/common/content/double_model/attributable/base.rb,
lib/ecoportal/api/common/content/double_model/modifiers/rootable.rb,
lib/ecoportal/api/common/content/double_model/attributable/simple.rb,
lib/ecoportal/api/common/content/double_model/attributable/enforce.rb,
lib/ecoportal/api/common/content/double_model/attributable/nesting.rb,
lib/ecoportal/api/common/content/double_model/double_doc/rooted_key.rb,
lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb,
lib/ecoportal/api/common/content/double_model/attributable/passthrough.rb,
lib/ecoportal/api/common/content/double_model/modifiers/read_only_able.rb,
lib/ecoportal/api/common/content/double_model/double_doc/replaceable_doc.rb,
lib/ecoportal/api/common/content/double_model/double_doc/reset_consolidate.rb

Overview

Basic model class, to build get / set methods for a given property which differs of attr_* ruby native class methods because pass* completelly links the methods to a subjacent Hash model

Defined Under Namespace

Modules: Attributable, Base, Diffable, DoubleDoc, HashHelpers, Modifiers, Parented, VarTracking

Constant Summary

Constants included from Diffable

Diffable::DIFF_CLASS

Constants included from Base

Base::NOT_USED

Instance Attribute Summary

Attributes included from Parented

#_parent, #_parent_key

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Diffable

#as_update, #dirty?

Methods included from Includer

#include_missing

Constructor Details

#initialize(doc = {}, parent: self, key: nil, read_only: self.class.read_only?) ⇒ DoubleModel

rubocop:disable Lint/MissingSuper



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ecoportal/api/common/content/double_model.rb', line 34

def initialize(doc = {}, parent: self, key: nil, read_only: self.class.read_only?) # rubocop:disable Lint/MissingSuper

  self._parent     = parent || self
  self._parent_key = key    || self

  read_only! if read_only

  self.class.enforce!(doc)

  if to_be_root?
    @doc             = JSON.parse(doc.to_json)
    @original_doc    = JSON.parse(@doc.to_json)
  end

  return unless key_method? && doc.is_a?(Hash)

  # ensure it is well linked! (so: throw error if something is wrong!)

  # and ensure the below does not create an infinite loop

  self.key = doc[key_method]
  #puts "\n$(#{self.key}<=>#{self.class})"

end

Class Method Details

.new_uuid(length: 24) ⇒ Object



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

def new_uuid(length: 24)
  uid(length)
end