Class: Mxrb::Model::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/model/unit.rb

Overview

Base for all Mendix artefacts. Each subclass maps to a unit row whose Contents BSON has a specific $Type.

Direct Known Subclasses

DomainModel, Menu, Microflow, Module, Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, mpr) ⇒ Unit

Returns a new instance of Unit.



12
13
14
15
16
17
18
19
20
# File 'lib/mxrb/model/unit.rb', line 12

def initialize(raw, mpr)
  @id               = raw["UnitID"]
  @container_id     = raw["ContainerID"]
  @containment_name = raw["ContainmentName"]
  @mpr              = mpr
  doc               = mpr.parse_contents(raw)
  @bson_type        = doc["$Type"] || doc["\$Type"]
  decode(doc)
end

Instance Attribute Details

#bson_typeObject (readonly)

Returns the value of attribute bson_type.



10
11
12
# File 'lib/mxrb/model/unit.rb', line 10

def bson_type
  @bson_type
end

#container_idObject (readonly)

Returns the value of attribute container_id.



10
11
12
# File 'lib/mxrb/model/unit.rb', line 10

def container_id
  @container_id
end

#containment_nameObject (readonly)

Returns the value of attribute containment_name.



10
11
12
# File 'lib/mxrb/model/unit.rb', line 10

def containment_name
  @containment_name
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/mxrb/model/unit.rb', line 10

def id
  @id
end

#mprObject (readonly)

Returns the value of attribute mpr.



10
11
12
# File 'lib/mxrb/model/unit.rb', line 10

def mpr
  @mpr
end

Instance Method Details

#decode(_doc) ⇒ Object

Subclasses implement these



23
# File 'lib/mxrb/model/unit.rb', line 23

def decode(_doc); end

#save!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mxrb/model/unit.rb', line 26

def save!
  doc = to_bson
  if @id
    @mpr.update_unit(@id, doc)
  else
    raise "Cannot insert without container_id" unless @container_id
    @id = @mpr.insert_unit(
      container_uuid:   @container_id,
      containment_name: @containment_name,
      contents_doc:     doc
    )
  end
  self
end

#to_bsonObject

Raises:

  • (NotImplementedError)


24
# File 'lib/mxrb/model/unit.rb', line 24

def to_bson;      raise NotImplementedError, "#{self.class}#to_bson not implemented"; end