Class: Blufin::YmlJavaEnumWriter
- Inherits:
-
YmlWriterBase
- Object
- YmlWriterBase
- Blufin::YmlJavaEnumWriter
- Defined in:
- lib/core/yml_writers/yml_java_enum_writer.rb
Constant Summary collapse
- SERVICE =
Blufin::SiteServices::SDK_INTERNAL
- PACKAGE_AUTO =
'enums'
- PACKAGE_CUSTOM =
'enums'
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, schema_data) ⇒ Object
constructor
Void.
-
#write ⇒ Object
Void.
Methods inherited from YmlWriterBase
#get_base_path, #get_java_path, #get_package, #get_package_from_file, #write_file_java
Constructor Details
#initialize(site, schema_data) ⇒ Object
Returns void.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/core/yml_writers/yml_java_enum_writer.rb', line 10 def initialize(site, schema_data) @schema_data = schema_data raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash) @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)}/" # Wipe out all previous files. Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema| paths_to_wipe_out = %W(#{get_java_path(@site, schema, SERVICE, PACKAGE_AUTO)}) paths_to_wipe_out.each do |path_to_wipe_out| if Blufin::Files::path_exists(path_to_wipe_out) if Blufin::Files::get_files_in_dir(path_to_wipe_out).any? Blufin::Terminal::command('rm *', path_to_wipe_out, false, false) end end end end end |
Instance Method Details
#write ⇒ Object
Returns void.
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 |
# File 'lib/core/yml_writers/yml_java_enum_writer.rb', line 37 def write @schema_data.each do |schema, schema_data| schema_data.each_with_index do |(table, table_data), idx| if table_data.length > 0 table_data.each do |column_name, column_data| # Skip Placeholders next if column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/ || column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/ field_camel_case = Blufin::Strings.snake_case_to_camel_case(column_name.dup) @type = column_data[Blufin::YmlSchemaValidator::TYPE] if @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM enum_class_name = "#{Blufin::Strings::snake_case_to_camel_case(table)}#{field_camel_case}" write_enum_class(enum_class_name, @type, schema) elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM enum_value = Blufin::YmlCommon::enum_name_extractor(@type) enum_file = "#{get_java_path(@site, schema, Blufin::SiteServices::SDK_CORE, PACKAGE_CUSTOM)}/#{enum_value}.java" write_enum_custom_class(enum_value, schema) unless Blufin::Files::file_exists(enum_file) end end end end end end |