Class: Camunda::Generators::BpmnClassesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/camunda/bpmn_classes/bpmn_classes_generator.rb

Overview

Parses the BPMN file and creates task classes according to the ID of the process file and the ID of each task. It checks each task and only creates it if the topic name is the same as the process ID. This allows one to have some tasks be handled outside the Rails app. It confirms that the ID’s are valid Ruby constant names.

Instance Method Summary collapse

Instance Method Details

#create_classesObject

Creates the correct classes from the bpmn file to be used in the provided generator template for the classes needed to run external tasks.



34
35
36
37
38
39
# File 'lib/generators/camunda/bpmn_classes/bpmn_classes_generator.rb', line 34

def create_classes
  bpmn_xml.class_names_with_same_bpmn_id_as_topic.each do |class_name|
    template 'bpmn_class.rb.template',
             File.join(model_path, module_name.underscore, "#{class_name.underscore}.rb"), class_name: class_name
  end
end

#create_moduleObject

Creates module names to be used for the task classes to perform external tasks.



28
29
30
# File 'lib/generators/camunda/bpmn_classes/bpmn_classes_generator.rb', line 28

def create_module
  template 'bpmn_module.rb.template', File.join(model_path, "#{module_name.underscore}.rb")
end

#validate_class_namesObject

Creates a class name to be used for the task classes created to perform external tasks.



18
19
20
21
22
23
24
25
# File 'lib/generators/camunda/bpmn_classes/bpmn_classes_generator.rb', line 18

def validate_class_names
  bpmn_xml.modularized_class_names.each do |class_name|
    validate_constant_name(class_name.demodulize, module_name)
  end
  puts set_color("External tasks with the same topic name as the BPMN id will be created.", :bold)
  colorized_class_names = bpmn_xml.modularized_class_names.map! { |class_name| set_color class_name, :red }
  puts colorized_class_names.join("\n")
end

#validate_module_nameString

Returns The id of the BPMN process.

Returns:

  • (String)

    The id of the BPMN process



12
13
14
15
# File 'lib/generators/camunda/bpmn_classes/bpmn_classes_generator.rb', line 12

def validate_module_name
  puts "The id of the BPMN process is: #{colored_module_name}. That will be your module name."
  validate_constant_name(module_name)
end