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.



713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'lib/mxrb/dsl/builder.rb', line 713

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.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def associations
  @associations
end

#constantsObject (readonly)

Returns the value of attribute constants.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def constants
  @constants
end

#entitiesObject (readonly)

Returns the value of attribute entities.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def entities
  @entities
end

#enumerationsObject (readonly)

Returns the value of attribute enumerations.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def enumerations
  @enumerations
end

Returns the value of attribute menus.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def menus
  @menus
end

#microflowsObject (readonly)

Returns the value of attribute microflows.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def microflows
  @microflows
end

#module_rolesObject (readonly)

Returns the value of attribute module_roles.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def module_roles
  @module_roles
end

#nameObject (readonly)

Returns the value of attribute name.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def name
  @name
end

#nanoflowsObject (readonly)

Returns the value of attribute nanoflows.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def nanoflows
  @nanoflows
end

#native_documentsObject (readonly)

Returns the value of attribute native_documents.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def native_documents
  @native_documents
end

#pagesObject (readonly)

Returns the value of attribute pages.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def pages
  @pages
end

#repositoriesObject (readonly)

Returns the value of attribute repositories.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def repositories
  @repositories
end

#scheduled_eventsObject (readonly)

Returns the value of attribute scheduled_events.



709
710
711
# File 'lib/mxrb/dsl/builder.rb', line 709

def scheduled_events
  @scheduled_events
end

Instance Method Details

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



780
781
782
783
784
# File 'lib/mxrb/dsl/builder.rb', line 780

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



729
730
731
732
733
# File 'lib/mxrb/dsl/builder.rb', line 729

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

#enumeration(name, &block) ⇒ Object



774
775
776
777
778
# File 'lib/mxrb/dsl/builder.rb', line 774

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

#evaluate(path) ⇒ Object



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

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

#evaluate_dir(dir) ⇒ Object



921
922
923
924
925
# File 'lib/mxrb/dsl/builder.rb', line 921

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.



806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
# File 'lib/mxrb/dsl/builder.rb', line 806

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


741
742
743
744
745
# File 'lib/mxrb/dsl/builder.rb', line 741

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



751
752
753
754
755
# File 'lib/mxrb/dsl/builder.rb', line 751

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



747
748
749
# File 'lib/mxrb/dsl/builder.rb', line 747

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

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



757
758
759
760
761
# File 'lib/mxrb/dsl/builder.rb', line 757

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') ⇒ Object

Raises:

  • (ArgumentError)


794
795
796
797
798
799
800
801
# File 'lib/mxrb/dsl/builder.rb', line 794

def native_document(name, type:, deep_structure:, containment: 'Documents')
  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,
    doc: { '$Type' => type.to_s, 'Name' => name.to_s }.merge(deep_structure)
  }
end

#page(name, &block) ⇒ Object



735
736
737
738
739
# File 'lib/mxrb/dsl/builder.rb', line 735

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



763
764
765
# File 'lib/mxrb/dsl/builder.rb', line 763

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

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



767
768
769
770
771
772
# File 'lib/mxrb/dsl/builder.rb', line 767

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



786
787
788
789
790
791
792
# File 'lib/mxrb/dsl/builder.rb', line 786

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



927
928
929
930
931
932
933
934
935
# File 'lib/mxrb/dsl/builder.rb', line 927

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