Class: Mxrb::Model::Module

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

Overview

$Type: Projects$Module ContainmentName: "Modules"

Instance Attribute Summary collapse

Attributes inherited from Unit

#bson_type, #container_id, #containment_name, #id, #mpr

Instance Method Summary collapse

Methods inherited from Unit

#initialize, #save!

Constructor Details

This class inherits a constructor from Mxrb::Model::Unit

Instance Attribute Details

#app_store_guidObject (readonly)

Returns the value of attribute app_store_guid.



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

def app_store_guid
  @app_store_guid
end

#app_store_versionObject (readonly)

Returns the value of attribute app_store_version.



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

def app_store_version
  @app_store_version
end

#export_levelObject (readonly)

Returns the value of attribute export_level.



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

def export_level
  @export_level
end

#from_app_storeObject (readonly)

Returns the value of attribute from_app_store.



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

def from_app_store
  @from_app_store
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#sort_indexObject (readonly)

Returns the value of attribute sort_index.



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

def sort_index
  @sort_index
end

Instance Method Details

#associationsObject



43
# File 'lib/mxrb/model/module.rb', line 43

def associations = domain_model&.associations || []

#constantsObject



75
76
77
78
79
# File 'lib/mxrb/model/module.rb', line 75

def constants
  @constants ||= document_units
                 .select { |u| u[:type] == "Constants$Constant" }
                 .map { unit_to_doc(_1) }
end

#decode(doc) ⇒ Object



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

def decode(doc)
  @name              = doc["Name"]
  @sort_index        = doc["SortIndex"] || doc["NewSortIndex"]
  @from_app_store    = doc["FromAppStore"] == true
  @app_store_guid    = doc["AppStoreGuid"]
  @app_store_version = doc["AppStoreVersion"]
  @export_level      = doc["ExportLevel"] || "Hidden"
end

#domain_modelObject

── Children (resolved from Unit table by ContainerID) ────────────



35
36
37
38
39
40
# File 'lib/mxrb/model/module.rb', line 35

def domain_model
  @domain_model ||= begin
    raws = @mpr.units_by_containment("DomainModel").select { _1["ContainerID"] == @id }
    raws.empty? ? nil : DomainModel.new(raws.first, @mpr)
  end
end

#entitiesObject



42
# File 'lib/mxrb/model/module.rb', line 42

def entities    = domain_model&.entities    || []

#enumerationsObject



69
70
71
72
73
# File 'lib/mxrb/model/module.rb', line 69

def enumerations
  @enumerations ||= document_units
                    .select { |u| u[:type] == "Enumerations$Enumeration" }
                    .map { unit_to_doc(_1) }
end

#inspectObject



101
102
103
104
# File 'lib/mxrb/model/module.rb', line 101

def inspect
  "#<Mxrb::Module name=#{@name.inspect} entities=#{entities.size} " \
    "pages=#{pages.size} microflows=#{microflows.size}>"
end


63
64
65
66
67
# File 'lib/mxrb/model/module.rb', line 63

def menus
  @menus ||= document_units
             .select { |u| u[:type] == "Menus$MenuDocument" }
             .map { Menu.new(_1[:raw], @mpr) }
end

#microflowsObject



51
52
53
54
55
# File 'lib/mxrb/model/module.rb', line 51

def microflows
  @microflows ||= document_units
                  .select { |u| u[:type] == "Microflows$Microflow" }
                  .map { Microflow.new(_1[:raw], @mpr) }
end

#module_rolesObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/mxrb/model/module.rb', line 87

def module_roles
  @module_roles ||= begin
    raw = @mpr.children_of(@id).find { _1["ContainmentName"] == "ModuleSecurity" }
    if raw
      doc = @mpr.parse_contents(raw)
      parse_array(doc["ModuleRoles"]).map do |role|
        { name: role["Name"], description: role["Description"].to_s }
      end
    else
      []
    end
  end
end

#nanoflowsObject



57
58
59
60
61
# File 'lib/mxrb/model/module.rb', line 57

def nanoflows
  @nanoflows ||= document_units
                 .select { |u| u[:type] == "Microflows$Nanoflow" }
                 .map { Microflow.new(_1[:raw], @mpr) }
end

#pagesObject



45
46
47
48
49
# File 'lib/mxrb/model/module.rb', line 45

def pages
  @pages ||= document_units
             .select { |u| %w[Pages$Page Forms$Page].include?(u[:type]) }
             .map { Page.new(_1[:raw], @mpr) }
end

#scheduled_eventsObject



81
82
83
84
85
# File 'lib/mxrb/model/module.rb', line 81

def scheduled_events
  @scheduled_events ||= document_units
                        .select { |u| u[:type] == "ScheduledEvents$ScheduledEvent" }
                        .map { unit_to_doc(_1) }
end

#to_bsonObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/mxrb/model/module.rb', line 22

def to_bson
  {
    "$ID"          => @id,
    "$Type"        => "Projects$Module",
    "Name"         => @name,
    "SortIndex"    => @sort_index || 0,
    "FromAppStore" => @from_app_store || false,
    "ExportLevel"  => @export_level || "Hidden",
  }
end