Class: Mxrb::Model::Unit
- Inherits:
-
Object
- Object
- Mxrb::Model::Unit
- 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
Instance Attribute Summary collapse
-
#bson_type ⇒ Object
readonly
Returns the value of attribute bson_type.
-
#container_id ⇒ Object
readonly
Returns the value of attribute container_id.
-
#containment_name ⇒ Object
readonly
Returns the value of attribute containment_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#mpr ⇒ Object
readonly
Returns the value of attribute mpr.
Instance Method Summary collapse
-
#decode(_doc) ⇒ Object
Subclasses implement these.
-
#initialize(raw, mpr) ⇒ Unit
constructor
A new instance of Unit.
- #save! ⇒ Object
- #to_bson ⇒ Object
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_type ⇒ Object (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_id ⇒ Object (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_name ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/mxrb/model/unit.rb', line 10 def id @id end |
#mpr ⇒ Object (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_bson ⇒ Object
24 |
# File 'lib/mxrb/model/unit.rb', line 24 def to_bson; raise NotImplementedError, "#{self.class}#to_bson not implemented"; end |