class Blufin::YmlConfigValidator
Constants
- CRON
- DELETE
- GET
- GLOBAL
- GLOBAL_AUTHENTICATION
- MESSAGE
- MESSAGE_RECEIVER
- PATCH
- PLACEHOLDER_CLASS
- PLACEHOLDER_FIVE
- PLACEHOLDER_FOUR
- PLACEHOLDER_ONE
- PLACEHOLDER_PACKAGE
- PLACEHOLDER_SITE_DOMAIN
- PLACEHOLDER_SITE_NAME
- PLACEHOLDER_SIX
- PLACEHOLDER_THREE
- PLACEHOLDER_TWO
- POST
- PUT
- STRUCTURE
- TEMPLATE_WORKER
- VALID_METHODS
- WORKER
- WORKER_DESCRIPTION
- WORKER_PRIORITY
Attributes
config_data[RW]
Public Class Methods
get_cron_types()
click to toggle source
Get CronTypes(s) as Array from @@config_data. @return Array
# File lib/core/yml/config/yml_config_validator.rb, line 141 def self.get_cron_types if @@cron_types.nil? @@cron_types = {} if !@@config_data[CRON].nil? && @@config_data[CRON].keys.any? @@config_data[CRON].each do |key, data| @@cron_types[key] = data end end end @@cron_types end
get_message_types()
click to toggle source
Get MessageType(s) as Array from @@config_data. @return Array
# File lib/core/yml/config/yml_config_validator.rb, line 127 def self.get_message_types if @@message_types.nil? @@message_types = {} if !@@config_data[WORKER].nil? && @@config_data[WORKER].keys.any? @@config_data[WORKER].each do |key, data| @@message_types[key] = data end end end @@message_types end
new(site, error_handler)
click to toggle source
Initialize the class. @return void
# File lib/core/yml/config/yml_config_validator.rb, line 101 def initialize(site, error_handler) @site = Blufin::SiteResolver::validate_site(site) @site_path = Blufin::SiteResolver::get_site_location(@site) @site_name = Blufin::SiteResolver::get_site_name(@site) @site_domain = Blufin::SiteResolver::get_site_domain(@site) @error_handler = error_handler @config_file = "#{Blufin::SiteResolver::get_site_location(@site)}/#{Blufin::Site::PATH_TO_YML_CONFIG}/config.yml" @@message_types = nil @@cron_types = nil return unless Blufin::YmlCommon::validate_directory_structure(@site_path, Blufin::Site::PATH_TO_YML_CONFIG, %w(config.yml), [], @error_handler) @@config_data = validate_single_file(site, @config_file, STRUCTURE, error_handler) @@config_data = @@config_data[@config_file] @config_data = @@config_data validate_data end
Private Instance Methods
validate_cron()
click to toggle source
Validates -> “cron” section @return void
# File lib/core/yml/config/yml_config_validator.rb, line 208 def validate_cron cron_types = Blufin::YmlConfigValidator::get_cron_types return false unless cron_types.any? message_types = Blufin::YmlConfigValidator::get_message_types.keys cron_types.each do |key, value| @error_handler.add_error(Blufin::YmlErrorHandler::WORKER_MESSAGE_TYPE_NOT_FOUND, @config_file, CRON, "#{key}|#{MESSAGE}", value[MESSAGE]) unless message_types.include?(value[MESSAGE]) end end
validate_data()
click to toggle source
Custom validation only applicable to CONFIG YML definition(s). @return void
# File lib/core/yml/config/yml_config_validator.rb, line 157 def validate_data validate_global return unless validate_worker # Worker needs to go first because it contains all the "message" types. validate_cron end
validate_global()
click to toggle source
Validates -> “global” section @return void
# File lib/core/yml/config/yml_config_validator.rb, line 167 def validate_global if @@config_data[GLOBAL].is_a?(Hash) value = @@config_data[GLOBAL][GLOBAL_AUTHENTICATION] valid_auth_levels = Blufin::SiteAuth::AUTHENTICATION_LEVELS.keys # Make sure the AuthLevel is a valid value. unless valid_auth_levels.include?(value) @yml_error_handler.add_error(Blufin::YmlErrorHandler::FIELD_INVALID_VALUE, @config_file, GLOBAL, GLOBAL_AUTHENTICATION, valid_auth_levels.join(' ')) return end raise 'This error occurred because you forgot to run Blufin::SiteEmbedded::init() somewhere...' if Blufin::SiteEmbedded::get_data.nil? # Make sure the embedded object exists. valid_embedded_objects = Blufin::SiteEmbedded::get_data.keys expected_embedded_objects = Blufin::SiteAuth::AUTHENTICATION_LEVELS[value] expected_embedded_objects.each do |expected_embedded_object| @yml_error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_NOT_FOUND, @config_file, GLOBAL, GLOBAL_AUTHENTICATION, expected_embedded_object) unless valid_embedded_objects.include?(expected_embedded_object) end end end
validate_worker()
click to toggle source
Validates -> “worker” section Checks that the boiler-plate MessageType handlers exist and implement correct interface. @return void
# File lib/core/yml/config/yml_config_validator.rb, line 189 def validate_worker message_types = Blufin::YmlConfigValidator::get_message_types.keys return false unless message_types.any? content_hash = {} message_types.each do |snake_cased_string| class_name = "#{Blufin::Strings::snake_case_to_camel_case(snake_cased_string)}#{Blufin::YmlJavaWorkerWriter::MESSAGE_HANDLER}" message_type_camel_cased_lower = Blufin::Strings::snake_case_to_camel_case_lower(snake_cased_string) contents = TEMPLATE_WORKER contents = contents.gsub(PLACEHOLDER_PACKAGE, "#{@site_domain}.#{@site_name.gsub('-', '.')}.#{Blufin::SiteServices::WORKER}.messages.#{message_type_camel_cased_lower}".gsub(/^\./, '')) contents = contents.gsub(PLACEHOLDER_CLASS, class_name) content_hash[snake_cased_string] = [contents, [' return false;'], "#{class_name}.java"] end path = "#{Blufin::SiteResolver::path_to_java_worker(@site)}/src/main/java/#{@site_domain.gsub('.', '/')}/#{@site_name}/#{Blufin::SiteServices::WORKER}/messages" Blufin::YmlCommon::create_boilerplate_files(content_hash, path, @site, @error_handler) true end