Class: Blufin::YmlJavaWorkerWriter
- Inherits:
-
YmlWriterBase
- Object
- YmlWriterBase
- Blufin::YmlJavaWorkerWriter
- Defined in:
- lib/core/yml_writers/yml_java_worker_writer.rb
Constant Summary collapse
- SERVICE =
Blufin::SiteServices::WORKER
- PACKAGE =
'messages'- PLACEHOLDER_IMP =
'{{--PLACEHOLDER-IMP--}}'- PLACEHOLDER_PUT =
'{{--PLACEHOLDER-ONE--}}'- PLACEHOLDER_SITE_NAME =
'{{--SITE-NAME--}}'- PLACEHOLDER_SITE_DOMAIN =
'{{--SITE-DOMAIN--}}'- MESSAGE_HANDLER =
'MessageHandler'- MESSAGE_HANDLER_MAPPER =
'MessageHandlerMapper'
Constants inherited from YmlWriterBase
Blufin::YmlWriterBase::AUTO_TYPES, Blufin::YmlWriterBase::PLACEHOLDER_CLASS, Blufin::YmlWriterBase::PLACEHOLDER_IMPORT, Blufin::YmlWriterBase::PLACEHOLDER_PACKAGE, Blufin::YmlWriterBase::PLACEHOLDER_SCHEMA
Instance Method Summary collapse
-
#initialize(site) ⇒ Object
constructor
Initialize the class.
-
#write ⇒ Object
Write the file(s).
Methods inherited from YmlWriterBase
#get_base_path, #get_java_path, #get_package, #get_package_from_file, #write_file_java
Constructor Details
#initialize(site) ⇒ Object
Initialize the class.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/core/yml_writers/yml_java_worker_writer.rb', line 18 def initialize(site) @site = Blufin::SiteResolver::validate_site(site) @site_name = Blufin::SiteResolver::get_site_name(@site) @site_domain = Blufin::SiteResolver::get_site_domain(@site) @site_domain_gsub = @site_domain.strip == '' ? '' : "#{@site_domain}." @site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/" # Wipe out parent file. Blufin::Files::delete_file("#{get_java_path(@site, nil, SERVICE, PLACEHOLDER_PUT)}/#{MESSAGE_HANDLER_MAPPER}.java") @template_parent = "package \#{PLACEHOLDER_PACKAGE};\n\nimport org.blufin.worker.queue.MessageHandlerInterface;\nimport \#{PLACEHOLDER_SITE_DOMAIN}\#{PLACEHOLDER_SITE_NAME}.lib.enums.system.MessageType;\n\#{PLACEHOLDER_IMP}\n\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class \#{MESSAGE_HANDLER_MAPPER} {\n\n public static Map<String, MessageHandlerInterface> getMap() {\n\nMap<String, MessageHandlerInterface> map = new HashMap<>();\n\n\#{PLACEHOLDER_PUT}\n\nreturn map;\n }\n}\n" end |
Instance Method Details
#write ⇒ Object
Write the file(s).
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/core/yml_writers/yml_java_worker_writer.rb', line 56 def write imp_statements = '' put_statements = '' = Blufin::YmlConfigValidator::.keys .each_with_index do |, idx| new_line_or_not = (idx == (.length - 1)) ? '' : "\n" imp_statements += "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.worker.messages.#{Blufin::Strings::snake_case_to_camel_case_lower(message_type)}.#{Blufin::Strings::snake_case_to_camel_case(message_type)}#{MESSAGE_HANDLER};#{new_line_or_not}" put_statements += " map.put(MessageType.#{message_type.upcase.gsub('-', '_')}.toString(), new #{Blufin::Strings::snake_case_to_camel_case(message_type)}#{MESSAGE_HANDLER}());#{new_line_or_not}" end contents = @template_parent contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, PACKAGE, SERVICE)) contents = contents.gsub(PLACEHOLDER_IMP, imp_statements) contents = contents.gsub(PLACEHOLDER_PUT, put_statements) contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.')) contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub) write_file_java("#{get_java_path(@site, nil, SERVICE, PACKAGE)}/#{MESSAGE_HANDLER_MAPPER}.java", Blufin::YmlCommon::convert_string_to_line_array(contents)) end |