Class: Blufin::YmlJavaMessageTypeWriter
- Inherits:
-
YmlWriterBase
- Object
- YmlWriterBase
- Blufin::YmlJavaMessageTypeWriter
- Defined in:
- lib/core/yml_writers/yml_java_message_type_writer.rb
Constant Summary collapse
- SERVICE =
Blufin::SiteServices::LIB
- PACKAGE =
'enums.system'
- PLACEHOLDER_ONE =
'{{--PLACEHOLDER-ONE--}}'
- PLACEHOLDER_TWO =
'{{--PLACEHOLDER-TWO--}}'
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.
13 14 15 16 17 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/core/yml_writers/yml_java_message_type_writer.rb', line 13 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_location = "#{Blufin::SiteResolver::get_site_location(@site)}/" @class_name = 'MessageType' @filename = "#{get_java_path(@site, nil, SERVICE, PACKAGE)}/#{@class_name}.java" # Wipe out previous file (if exists). Blufin::Files::delete_file(@filename) @template = <<TEMPLATE package #{PLACEHOLDER_PACKAGE}; import org.blufin.base.interfaces.AbstractMessageType; import lombok.Getter; import java.util.HashMap; import java.util.Map; public enum #{@class_name} implements AbstractMessageType { #{PLACEHOLDER_ONE} private static final Map<String, #{@class_name}> map = new HashMap<>(); @Getter private String name; static { #{PLACEHOLDER_TWO} } /** * @param name */ #{@class_name}(String name) { this.name = name; } /** * Get MessageType by its String representation. * @param name */ public static MessageType get(String name) { return map.get(name); } @Override public String toString() { return name; } } TEMPLATE end |
Instance Method Details
#write ⇒ Object
Write the file(s).
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/core/yml_writers/yml_java_message_type_writer.rb', line 79 def write ph1 = [] ph2 = [] = Blufin::YmlConfigValidator::.keys # Don't write the class if there are no message types. return if .nil? || .length == 0 .each_with_index do |, idx| comma_or_semicolon = (idx == (.length - 1)) ? ';' : ',' ph1 << " #{.upcase}(\"#{.upcase}\")#{comma_or_semicolon}" ph2 << " map.put(\"#{.upcase}\", MessageType.#{.upcase});" end contents = @template contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, PACKAGE, SERVICE)) contents = contents.gsub(PLACEHOLDER_ONE, Blufin::YmlCommon::convert_line_array_to_string(ph1)) contents = contents.gsub(PLACEHOLDER_TWO, Blufin::YmlCommon::convert_line_array_to_string(ph2)) write_file_java(@filename, Blufin::YmlCommon::convert_string_to_line_array(contents)) end |