Class: Blufin::ScannerJavaEnums
- Inherits:
-
Object
- Object
- Blufin::ScannerJavaEnums
- Defined in:
- lib/core/code_scanners/scanner_java_enums.rb
Constant Summary collapse
- @@enum_scanned =
false
- @@enum_auto =
nil
- @@enum_custom =
nil
- @@enum_system =
nil
Instance Method Summary collapse
-
#get_auto_enums ⇒ Object
Returns a Hash with all of the Auto-generated ENUM data.
-
#get_custom_enums ⇒ Object
Returns a Hash with all of the Custom ENUM data.
-
#get_enum_custom_values_for(enum_name) ⇒ Object
Returns CUSTOM enum values as Array.
-
#get_enum_system_values_for(enum_name) ⇒ Object
Returns SYSTEM enum values as Array.
-
#get_system_enums ⇒ Object
Returns a Hash with all of the System ENUM data.
-
#initialize(site) ⇒ Object
constructor
Read all enum values into class variable – shard between instances meaning re-instantiating the class won’t require re-scanning enums.
Constructor Details
#initialize(site) ⇒ Object
Read all enum values into class variable – shard between instances meaning re-instantiating the class won’t require re-scanning enums.
12 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 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/core/code_scanners/scanner_java_enums.rb', line 12 def initialize(site) @site = Blufin::SiteResolver::validate_site(site) unless @@enum_scanned directories = %W( #{Blufin::SiteResolver::path_to_java_sdk_core(@site)}/src/main/java/#{Blufin::SiteResolver::get_site_domain(@site)}/#{Blufin::SiteResolver::get_site_name(@site)}/sdk/enums #{Blufin::SiteResolver::path_to_blufin_java}/blufin-base/src/main/java/#{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS.gsub('.', '/')} ) directories.each_with_index do |directory_data, idx| hash = {} hash_nested = {} if Blufin::Files::path_exists(directory_data) Blufin::Files::get_files_in_dir(directory_data).each do |file| enum_title = nil enum_exists = false Blufin::Files::read_file(file).each do |line| # If line matches "public enum XXX {" if enum_exists == false && line.strip =~ /public\s+enum\s+[A-Za-z0-9]+\s*\{/ enum_exists = true enum_title = line.strip.gsub(/public\s+enum\s+/, '').gsub(/\s*\{/, '') hash[enum_title] = [] hash_nested[enum_title] = (file.gsub(directory_data, '').gsub(/\A\//, '').split('/').length > 1) ? true : false end # Extract ENUM values and put them inside @enum hash. if enum_exists if line.strip =~ /\A[A-Z_]+(\(.*\))*(,|;|)\z/ matcher = line.strip.match(/\A[A-Z_]+/) hash[enum_title] << matcher[0] elsif line.strip =~ /\A[A-Z_,\s]+(,|;|)\z/ line.strip.split(',').each do |value| hash[enum_title] << value.strip end end end end end end if idx == 0 @@enum_auto = {} @@enum_custom = {} hash.each do |key, value| if hash_nested[key] @@enum_auto[key] = value else @@enum_custom[key] = value end end elsif idx == 1 @@enum_system = hash end end @@enum_scanned = true end end |
Instance Method Details
#get_auto_enums ⇒ Object
Returns a Hash with all of the Auto-generated ENUM data.
107 108 109 |
# File 'lib/core/code_scanners/scanner_java_enums.rb', line 107 def get_auto_enums @@enum_auto end |
#get_custom_enums ⇒ Object
Returns a Hash with all of the Custom ENUM data.
113 114 115 |
# File 'lib/core/code_scanners/scanner_java_enums.rb', line 113 def get_custom_enums @@enum_custom end |
#get_enum_custom_values_for(enum_name) ⇒ Object
Returns CUSTOM enum values as Array.
92 93 94 95 96 |
# File 'lib/core/code_scanners/scanner_java_enums.rb', line 92 def get_enum_custom_values_for(enum_name) raise RuntimeError, "#{enum_name} has not been found to be a CUSTOM_ENUM" unless @@enum_custom.has_key?(enum_name) @@enum_custom[enum_name] end |
#get_enum_system_values_for(enum_name) ⇒ Object
Returns SYSTEM enum values as Array.
100 101 102 103 |
# File 'lib/core/code_scanners/scanner_java_enums.rb', line 100 def get_enum_system_values_for(enum_name) raise RuntimeError, "#{enum_name} has not been found to be a SYSTEM_ENUM" unless @@enum_system.has_key?(enum_name) @@enum_system[enum_name] end |
#get_system_enums ⇒ Object
Returns a Hash with all of the System ENUM data.
119 120 121 |
# File 'lib/core/code_scanners/scanner_java_enums.rb', line 119 def get_system_enums @@enum_system end |