Class: Mxrb::Dsl::ModuleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/dsl/builder.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ModuleBuilder

Returns a new instance of ModuleBuilder.



825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'lib/mxrb/dsl/builder.rb', line 825

def initialize(name)
  @name             = name.to_s
  @entities         = []
  @pages            = []
  @microflows       = []
  @nanoflows        = []
  @repositories     = []
  @associations     = []
  @menus            = []
  @module_roles     = []
  @enumerations     = []
  @constants        = []
  @scheduled_events = []
  @native_documents = []
end

Instance Attribute Details

#associationsObject (readonly)

Returns the value of attribute associations.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def associations
  @associations
end

#constantsObject (readonly)

Returns the value of attribute constants.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def constants
  @constants
end

#entitiesObject (readonly)

Returns the value of attribute entities.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def entities
  @entities
end

#enumerationsObject (readonly)

Returns the value of attribute enumerations.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def enumerations
  @enumerations
end

Returns the value of attribute menus.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def menus
  @menus
end

#microflowsObject (readonly)

Returns the value of attribute microflows.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def microflows
  @microflows
end

#module_rolesObject (readonly)

Returns the value of attribute module_roles.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def module_roles
  @module_roles
end

#nameObject (readonly)

Returns the value of attribute name.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def name
  @name
end

#nanoflowsObject (readonly)

Returns the value of attribute nanoflows.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def nanoflows
  @nanoflows
end

#native_documentsObject (readonly)

Returns the value of attribute native_documents.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def native_documents
  @native_documents
end

#pagesObject (readonly)

Returns the value of attribute pages.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def pages
  @pages
end

#repositoriesObject (readonly)

Returns the value of attribute repositories.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def repositories
  @repositories
end

#scheduled_eventsObject (readonly)

Returns the value of attribute scheduled_events.



821
822
823
# File 'lib/mxrb/dsl/builder.rb', line 821

def scheduled_events
  @scheduled_events
end

Instance Method Details

#bson_binary(base64, subtype: :generic) ⇒ Object



917
918
919
# File 'lib/mxrb/dsl/builder.rb', line 917

def bson_binary(base64, subtype: :generic)
  BSON::Binary.new(Base64.strict_decode64(base64), subtype.to_sym)
end

#constant(name, type:, value: nil, &block) ⇒ Object



892
893
894
895
896
# File 'lib/mxrb/dsl/builder.rb', line 892

def constant(name, type:, value: nil, &block)
  cb = ConstantBuilder.new(name, type: type, value: value)
  cb.instance_eval(&block) if block
  @constants << cb.to_h
end

#entity(name, &block) ⇒ Object



841
842
843
844
845
# File 'lib/mxrb/dsl/builder.rb', line 841

def entity(name, &block)
  eb = EntityBuilder.new(name)
  eb.instance_eval(&block) if block
  @entities << eb.to_h
end

#enumeration(name, &block) ⇒ Object



886
887
888
889
890
# File 'lib/mxrb/dsl/builder.rb', line 886

def enumeration(name, &block)
  eb = EnumerationBuilder.new(name)
  eb.instance_eval(&block) if block
  @enumerations << eb.to_h
end

#evaluate(path) ⇒ Object



1035
1036
1037
# File 'lib/mxrb/dsl/builder.rb', line 1035

def evaluate(path)
  instance_eval(File.read(path), path, 1)
end

#evaluate_dir(dir) ⇒ Object



1039
1040
1041
1042
1043
# File 'lib/mxrb/dsl/builder.rb', line 1039

def evaluate_dir(dir)
  return unless File.directory?(dir)

  Dir[File.join(dir, '*.rb')].sort.each { |path| evaluate(path) }
end

#layout(name = :ApplicationLayout, title: nil, navigation: :Responsive) ⇒ Object

Native responsive application shell. It deliberately uses only Mendix core widgets, so generated projects do not depend on Atlas Core merely to display their navigation.



924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
# File 'lib/mxrb/dsl/builder.rb', line 924

def layout(name = :ApplicationLayout, title: nil, navigation: :Responsive)
  appearance = lambda do |class_name = ''|
    {
      '$ID' => SecureRandom.uuid, '$Type' => 'Forms$Appearance',
      'Class' => class_name, 'DesignProperties' => IO::BsonCodec.build_array([]),
      'DynamicClasses' => '', 'Style' => ''
    }
  end
  placeholder = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$Placeholder',
    'Appearance' => appearance.call, 'Name' => 'Main', 'TabIndex' => 0
  }
  text = lambda do |value|
    {
      '$ID' => SecureRandom.uuid, '$Type' => 'Texts$Text',
      'Items' => IO::BsonCodec.build_array([
                                             {
                                               '$ID' => SecureRandom.uuid, '$Type' => 'Texts$Translation',
                                               'LanguageCode' => 'en_US', 'Text' => value.to_s
                                             }
                                           ])
    }
  end
  client_template = lambda do |value|
    {
      '$ID' => SecureRandom.uuid, '$Type' => 'Forms$ClientTemplate',
      'Fallback' => text.call(''),
      'Parameters' => IO::BsonCodec.build_array([], marker: 2),
      'Template' => text.call(value)
    }
  end
  no_action = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$NoAction',
    'DisabledDuringExecution' => true
  }
  navigation_tree = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$NavigationTree',
    'Appearance' => appearance.call('mxrb-navigation'),
    'MenuSource' => {
      '$ID' => SecureRandom.uuid, '$Type' => 'Forms$NavigationSource',
      'NavigationProfile' => navigation.to_s
    },
    'Name' => 'navigationTree1', 'TabIndex' => 0
  }
  left = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$ScrollContainerRegion',
    'Appearance' => appearance.call('region-sidebar'),
    'Size' => 264, 'SizeMode' => 'Pixels',
    'ToggleMode' => 'ShrinkContentInitiallyClosed',
    'Widgets' => IO::BsonCodec.build_array([navigation_tree], marker: 2)
  }
  sidebar_toggle = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$SidebarToggleButton',
    'Appearance' => appearance.call('mxrb-sidebar-toggle'),
    'ButtonStyle' => 'Primary', 'CaptionTemplate' => client_template.call('Menu'),
    'ConditionalVisibilitySettings' => nil, 'Icon' => nil,
    'Name' => 'sidebarToggle1', 'RenderType' => 'Button', 'TabIndex' => 0,
    'Tooltip' => text.call('Toggle navigation')
  }
  brand = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$DynamicText',
    'Appearance' => appearance.call('mxrb-brand'), 'Class' => '',
    'ConditionalVisibilitySettings' => nil,
    'Content' => client_template.call(title || name.to_s),
    'Name' => 'applicationTitle', 'NativeAccessibilitySettings' => nil,
    'NativeTextStyle' => 'Text', 'RenderMode' => 'Text', 'Style' => '',
    'TabIndex' => 0
  }
  topbar_content = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$DivContainer',
    'Appearance' => appearance.call('mxrb-topbar'),
    'ConditionalVisibilitySettings' => nil, 'Name' => 'topbarContent',
    'OnClickAction' => no_action, 'RenderMode' => 'Div',
    'ScreenReaderHidden' => false, 'TabIndex' => 0,
    'Widgets' => IO::BsonCodec.build_array([sidebar_toggle, brand], marker: 2)
  }
  top = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$ScrollContainerRegion',
    'Appearance' => appearance.call('region-topbar'),
    'Size' => 72, 'SizeMode' => 'Pixels', 'ToggleMode' => 'None',
    'Widgets' => IO::BsonCodec.build_array([topbar_content], marker: 2)
  }
  center = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$ScrollContainerRegion',
    'Appearance' => appearance.call('region-content'),
    'Size' => 200, 'SizeMode' => 'Auto',
    'ToggleMode' => 'None',
    'Widgets' => IO::BsonCodec.build_array([placeholder], marker: 2)
  }
  container = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$ScrollContainer',
    'Alignment' => 'Center', 'Bottom' => nil, 'CenterRegion' => center,
    'Appearance' => appearance.call, 'LayoutMode' => 'Headline', 'Left' => left,
    'Name' => 'scrollContainer1', 'Right' => nil, 'ScrollBehavior' => 'PerRegion',
    'NativeHideScrollbars' => false, 'TabIndex' => 0, 'Top' => top,
    'Width' => 960, 'WidthMode' => 'Auto'
  }
  content = {
    '$ID' => SecureRandom.uuid, '$Type' => 'Forms$WebLayoutContent',
    'LayoutCall' => nil, 'LayoutType' => 'Responsive',
    'Widgets' => IO::BsonCodec.build_array([container], marker: 2)
  }
  native_document(
    name, type: 'Forms$Layout', deep_structure: {
      'Appearance' => appearance.call('mxrb-application-shell'), 'CanvasHeight' => 600,
      'CanvasWidth' => 800, 'Content' => content, 'Documentation' => '',
      'Excluded' => false, 'ExportLevel' => 'Hidden'
    }
  )
end


853
854
855
856
857
# File 'lib/mxrb/dsl/builder.rb', line 853

def menu(name, &block)
  mb = MenuBuilder.new(name)
  mb.instance_eval(&block) if block
  @menus << mb.to_h
end

#microflow(name, kind: :use_case, public: false, &block) ⇒ Object



863
864
865
866
867
# File 'lib/mxrb/dsl/builder.rb', line 863

def microflow(name, kind: :use_case, public: false, &block)
  fb = FlowBuilder.new(name, runtime: :server, kind: kind, public: public)
  fb.instance_eval(&block) if block
  @microflows << fb.to_h
end

#module_role(name, description: "") ⇒ Object



859
860
861
# File 'lib/mxrb/dsl/builder.rb', line 859

def module_role(name, description: "")
  @module_roles << { name: name.to_s, description: description.to_s }
end

#nanoflow(name, public: false, &block) ⇒ Object



869
870
871
872
873
# File 'lib/mxrb/dsl/builder.rb', line 869

def nanoflow(name, public: false, &block)
  fb = FlowBuilder.new(name, runtime: :client, kind: :client_action, public: public)
  fb.instance_eval(&block) if block
  @nanoflows << fb.to_h
end

#native_document(name, type:, deep_structure:, containment: 'Documents', unit_id: nil, container_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


906
907
908
909
910
911
912
913
914
915
# File 'lib/mxrb/dsl/builder.rb', line 906

def native_document(name, type:, deep_structure:, containment: 'Documents',
                    unit_id: nil, container_id: nil)
  raise ArgumentError, 'deep_structure requires a Hash' unless deep_structure.is_a?(Hash)

  @native_documents << {
    name: name.to_s, type: type.to_s, containment: containment.to_s,
    unit_id: unit_id&.to_s, container_id: container_id&.to_s,
    doc: { '$Type' => type.to_s, 'Name' => name.to_s }.merge(deep_structure)
  }
end

#page(name, &block) ⇒ Object



847
848
849
850
851
# File 'lib/mxrb/dsl/builder.rb', line 847

def page(name, &block)
  pb = PageBuilder.new(name)
  pb.instance_eval(&block) if block
  @pages << pb.to_h
end

#query(name, public: false, &block) ⇒ Object



875
876
877
# File 'lib/mxrb/dsl/builder.rb', line 875

def query(name, public: false, &block)
  microflow(name, kind: :query, public: public, &block)
end

#repository(name, implementation: nil, public: false, documentation: "") ⇒ Object



879
880
881
882
883
884
# File 'lib/mxrb/dsl/builder.rb', line 879

def repository(name, implementation: nil, public: false, documentation: "")
  @repositories << {
    name: name.to_s, implementation: implementation&.to_s,
    public: public, documentation: documentation.to_s
  }
end

#scheduled_event(name, microflow:, interval: 1, unit: :days, enabled: true, &block) ⇒ Object



898
899
900
901
902
903
904
# File 'lib/mxrb/dsl/builder.rb', line 898

def scheduled_event(name, microflow:, interval: 1, unit: :days, enabled: true, &block)
  sb = ScheduledEventBuilder.new(
    name, microflow: microflow, interval: interval, unit: unit, enabled: enabled
  )
  sb.instance_eval(&block) if block
  @scheduled_events << sb.to_h
end

#to_hObject



1045
1046
1047
1048
1049
1050
1051
1052
1053
# File 'lib/mxrb/dsl/builder.rb', line 1045

def to_h
  {
    name: @name, entities: @entities, pages: @pages,
    microflows: @microflows, nanoflows: @nanoflows,
    repositories: @repositories, menus: @menus, module_roles: @module_roles,
    enumerations: @enumerations, constants: @constants,
    scheduled_events: @scheduled_events, native_documents: @native_documents
  }
end