Class: Mxrb::Model::Attribute
- Inherits:
-
Object
- Object
- Mxrb::Model::Attribute
- Defined in:
- lib/mxrb/model/attribute.rb
Overview
Attributes are embedded in Entity BSON — NOT separate Unit rows. $Type: DomainModels$Attribute
Constant Summary collapse
- TYPE_MAP =
Maps DSL symbol → Mendix storage type name
{ string: "DomainModels$StringAttributeType", integer: "DomainModels$IntegerAttributeType", long: "DomainModels$LongAttributeType", float: "DomainModels$FloatAttributeType", decimal: "DomainModels$DecimalAttributeType", boolean: "DomainModels$BooleanAttributeType", datetime: "DomainModels$DateTimeAttributeType", autonumber: "DomainModels$AutoNumberAttributeType", hashstring: "DomainModels$HashedStringAttributeType", binary: "DomainModels$BinaryAttributeType", enum: "DomainModels$EnumerationAttributeType", }.freeze
- REVERSE_TYPE_MAP =
TYPE_MAP.invert.freeze
Instance Attribute Summary collapse
-
#data_storage_guid ⇒ Object
Returns the value of attribute data_storage_guid.
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#documentation ⇒ Object
Returns the value of attribute documentation.
-
#enumeration ⇒ Object
Returns the value of attribute enumeration.
-
#export_level ⇒ Object
Returns the value of attribute export_level.
-
#id ⇒ Object
Returns the value of attribute id.
-
#length ⇒ Object
Returns the value of attribute length.
-
#localize_date ⇒ Object
Returns the value of attribute localize_date.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw_type_doc ⇒ Object
Returns the value of attribute raw_type_doc.
-
#raw_value_doc ⇒ Object
Returns the value of attribute raw_value_doc.
-
#required ⇒ Object
Returns the value of attribute required.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unique ⇒ Object
Returns the value of attribute unique.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#data_storage_guid ⇒ Object
Returns the value of attribute data_storage_guid.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def data_storage_guid @data_storage_guid end |
#default_value ⇒ Object
Returns the value of attribute default_value.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def default_value @default_value end |
#documentation ⇒ Object
Returns the value of attribute documentation.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def documentation @documentation end |
#enumeration ⇒ Object
Returns the value of attribute enumeration.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def enumeration @enumeration end |
#export_level ⇒ Object
Returns the value of attribute export_level.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def export_level @export_level end |
#id ⇒ Object
Returns the value of attribute id.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def id @id end |
#length ⇒ Object
Returns the value of attribute length.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def length @length end |
#localize_date ⇒ Object
Returns the value of attribute localize_date.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def localize_date @localize_date end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def name @name end |
#raw_type_doc ⇒ Object
Returns the value of attribute raw_type_doc.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def raw_type_doc @raw_type_doc end |
#raw_value_doc ⇒ Object
Returns the value of attribute raw_value_doc.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def raw_value_doc @raw_value_doc end |
#required ⇒ Object
Returns the value of attribute required.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def required @required end |
#type ⇒ Object
Returns the value of attribute type.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def type @type end |
#unique ⇒ Object
Returns the value of attribute unique.
27 28 29 |
# File 'lib/mxrb/model/attribute.rb', line 27 def unique @unique end |
Class Method Details
.extract_default(value_doc) ⇒ Object
79 80 81 82 |
# File 'lib/mxrb/model/attribute.rb', line 79 def self.extract_default(value_doc) return nil unless value_doc.is_a?(Hash) value_doc["defaultValue"] || value_doc["DefaultValue"] end |
.from_bson(doc) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mxrb/model/attribute.rb', line 31 def self.from_bson(doc) a = new a.id = IO::BsonCodec.extract_id(doc["$ID"] || doc["\$ID"]) a.name = doc["name"] || doc["Name"] a.documentation = doc["documentation"] || doc["Documentation"] || "" a.data_storage_guid = doc["dataStorageGuid"] || doc["DataStorageGuid"] a.export_level = doc["exportLevel"] || doc["ExportLevel"] || "Hidden" type_doc = doc["type"] || doc["Type"] || doc["newType"] || doc["NewType"] a.raw_type_doc = type_doc if type_doc.is_a?(Hash) storage_type = type_doc["$Type"] || type_doc["\$Type"] a.type = REVERSE_TYPE_MAP[storage_type] || :string a.length = type_doc['length'] || type_doc['Length'] a.localize_date = if type_doc.key?('localizeDate') type_doc['localizeDate'] else type_doc['LocalizeDate'] end a.enumeration = type_doc['enumeration'] || type_doc['Enumeration'] else a.type = :string end a.raw_value_doc = doc["value"] || doc["Value"] a.default_value = extract_default(a.raw_value_doc) a end |
Instance Method Details
#inspect ⇒ Object
73 74 75 |
# File 'lib/mxrb/model/attribute.rb', line 73 def inspect "#<Mxrb::Attribute name=#{@name.inspect} type=#{@type}>" end |
#to_bson ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mxrb/model/attribute.rb', line 60 def to_bson { "$ID" => @id || SecureRandom.uuid, "$Type" => "DomainModels$Attribute", "name" => @name, "documentation" => @documentation || "", "dataStorageGuid" => @data_storage_guid || SecureRandom.uuid, "exportLevel" => @export_level || "Hidden", "type" => serialize_type, "value" => serialize_value, } end |