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.



794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/mxrb/dsl/builder.rb', line 794

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.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def associations
  @associations
end

#constantsObject (readonly)

Returns the value of attribute constants.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def constants
  @constants
end

#entitiesObject (readonly)

Returns the value of attribute entities.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def entities
  @entities
end

#enumerationsObject (readonly)

Returns the value of attribute enumerations.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def enumerations
  @enumerations
end

Returns the value of attribute menus.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def menus
  @menus
end

#microflowsObject (readonly)

Returns the value of attribute microflows.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def microflows
  @microflows
end

#module_rolesObject (readonly)

Returns the value of attribute module_roles.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def module_roles
  @module_roles
end

#nameObject (readonly)

Returns the value of attribute name.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def name
  @name
end

#nanoflowsObject (readonly)

Returns the value of attribute nanoflows.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def nanoflows
  @nanoflows
end

#native_documentsObject (readonly)

Returns the value of attribute native_documents.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def native_documents
  @native_documents
end

#pagesObject (readonly)

Returns the value of attribute pages.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def pages
  @pages
end

#repositoriesObject (readonly)

Returns the value of attribute repositories.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def repositories
  @repositories
end

#scheduled_eventsObject (readonly)

Returns the value of attribute scheduled_events.



790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 790

def scheduled_events
  @scheduled_events
end

Instance Method Details

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



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

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

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



861
862
863
864
865
# File 'lib/mxrb/dsl/builder.rb', line 861

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



810
811
812
813
814
# File 'lib/mxrb/dsl/builder.rb', line 810

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

#enumeration(name, &block) ⇒ Object



855
856
857
858
859
# File 'lib/mxrb/dsl/builder.rb', line 855

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

#evaluate(path) ⇒ Object



1004
1005
1006
# File 'lib/mxrb/dsl/builder.rb', line 1004

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

#evaluate_dir(dir) ⇒ Object



1008
1009
1010
1011
1012
# File 'lib/mxrb/dsl/builder.rb', line 1008

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.



893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
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
# File 'lib/mxrb/dsl/builder.rb', line 893

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


822
823
824
825
826
# File 'lib/mxrb/dsl/builder.rb', line 822

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



832
833
834
835
836
# File 'lib/mxrb/dsl/builder.rb', line 832

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



828
829
830
# File 'lib/mxrb/dsl/builder.rb', line 828

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

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



838
839
840
841
842
# File 'lib/mxrb/dsl/builder.rb', line 838

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)


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

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



816
817
818
819
820
# File 'lib/mxrb/dsl/builder.rb', line 816

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



844
845
846
# File 'lib/mxrb/dsl/builder.rb', line 844

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

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



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

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



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

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



1014
1015
1016
1017
1018
1019
1020
1021
1022
# File 'lib/mxrb/dsl/builder.rb', line 1014

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