Class: Blufin::YmlValidatorBase
- Inherits:
-
Object
- Object
- Blufin::YmlValidatorBase
- Defined in:
- lib/core/yml/yml_validator_base.rb
Direct Known Subclasses
YmlConfigValidator, YmlMavenValidator, YmlResourceValidator, YmlSchemaValidator
Constant Summary collapse
- SECTION_MATCHES_FILENAME =
:section_matches_filename
- SECTION_TYPE_FIXED =
:section_type_fixed
- SECTION_TYPE_DYNAMIC =
:section_type_dynamic
- SECTION_TYPE_ARRAY =
:section_type_array
- FIELD_TYPE_ARRAY =
:field_type_array
- FIELD_TYPE_BOOLEAN =
:field_type_boolean
- FIELD_TYPE_FILE =
:field_type_file
- FIELD_TYPE_FLOAT =
:field_type_float
- FIELD_TYPE_TEXT =
:field_type_text
- FIELD_TYPE_BLANK =
:field_type_blank
- FIELD_TYPE_NESTED_DATA =
:field_type_nested_data
Instance Method Summary collapse
-
#validate(site, path, structure, error_handler, path_explicitly_defined = false) ⇒ Object
Does all the common validation before handing the data-hash back to the implementing class.
-
#validate_single_file(site, file, structure, error_handler) ⇒ Object
Same as above but with a single file.
Instance Method Details
#validate(site, path, structure, error_handler, path_explicitly_defined = false) ⇒ Object
Does all the common validation before handing the data-hash back to the implementing class. Any errors that occur during this phase will be added to global @yml_error array. Returns a Hash which is nothing more than a code representation of the YML data (and you can be 100% sure that it’s valid).
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/core/yml/yml_validator_base.rb', line 21 def validate(site, path, structure, error_handler, path_explicitly_defined = false) raise RuntimeError, "'path' must be either String or Array, instead got: #{path.class}" unless path.is_a?(Array) || path.is_a?(String) raise RuntimeError, '@yml_structure cannot be nil.' if structure.nil? @site = Blufin::SiteResolver::validate_site(site) @site_path = Blufin::SiteResolver::get_site_location(@site) @yml_structure = structure @yml_error_handler = error_handler @yml_path = [] paths = path.is_a?(String) ? [path] : path if path_explicitly_defined paths.each { |p| @yml_path << p } else paths.each { |p| @yml_path << "#{Blufin::SiteResolver::get_site_location(@site)}/#{p}" } end return_yml_data end |
#validate_single_file(site, file, structure, error_handler) ⇒ Object
Same as above but with a single file.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/core/yml/yml_validator_base.rb', line 47 def validate_single_file(site, file, structure, error_handler) raise RuntimeError, "'path' must be either String or Array, instead got: #{file.class}" unless file.is_a?(Array) || file.is_a?(String) raise RuntimeError, '@yml_structure cannot be nil.' if structure.nil? @site = Blufin::SiteResolver::validate_site(site) @site_path = Blufin::SiteResolver::get_site_location(@site) @yml_structure = structure @yml_error_handler = error_handler @yml_path = [] yml_data = validate_file_single(file) return if yml_data.nil? { file => yml_data } end |