class RokuBuilder::ConfigValidator
Constants
- DEPRICATED_FILES_FOLDERS
- DEVICE_DEFAULT_BAD
- DEVICE_MISSING_IP
- DEVICE_MISSING_PASSWORD
- DEVICE_MISSING_USER
- INVALID_MAPPING_INFO
- KEY_MISSING_PASSWORD
- KEY_MISSING_PATH
- MISSING_DEVICES
- MISSING_DEVICES_DEFAULT
- MISSING_PROJECTS_DEFAULT
4¶ ↑
- MISSING_STAGE_METHOD
22¶ ↑
- PROJECTS_DEFAULT_BAD
- PROJECT_FILES_BAD
- PROJECT_FOLDERS_BAD
- PROJECT_MISSING_APP_NAME
- PROJECT_MISSING_DIRECTORY
- PROJECT_MISSING_FILES
- PROJECT_MISSING_PLUGIN
- PROJECT_STAGE_METHOD_BAD
- STAGE_MISSING_BRANCH
- STAGE_MISSING_SCRIPT
- VALID_CONFIG
Public Class Methods
new(config:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 32 def initialize(config:) @logger = Logger.instance @config = config validate_config end
Public Instance Methods
is_depricated?()
click to toggle source
# File lib/roku_builder/config_validator.rb, line 53 def is_depricated? !@codes.select{|code| code < 0}.empty? end
is_fatal?()
click to toggle source
# File lib/roku_builder/config_validator.rb, line 49 def is_fatal? !@codes.select{|code| code > 0}.empty? end
is_valid?()
click to toggle source
# File lib/roku_builder/config_validator.rb, line 57 def is_valid? @codes.select{|code| code > 0}.empty? end
print_errors()
click to toggle source
# File lib/roku_builder/config_validator.rb, line 38 def print_errors @codes.each do |code| if code > 0 @logger.fatal error_codes[code] end if code < 0 @logger.warn error_codes[code] end end end
Private Instance Methods
call_validate_method_for_section(section:, content:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 87 def call_validate_method_for_section(section:, content:) section_singular = singularize(section: section.to_s) attrs = {} attrs[section_singular] = content method = "validate_#{section_singular}".to_sym send(method, **attrs) end
error_codes()
click to toggle source
# File lib/roku_builder/config_validator.rb, line 183 def error_codes [ #===============FATAL ERRORS===============# "Valid Config.", "Devices config is missing.", "Devices default is missing.", "Devices default is not a hash.", "", "Projects default is missing.", #5 "Projects default is not a hash.", "A device config is missing its IP address.", "A device config is missing its username.", "A device config is missing its password.", "A project config is missing its app_name.", #10 "A project config is missing its directorty.", "A project is missing its staging plugin", "A project config's folders is not an array.", "A project config is missing its files.", "A project config's files is not an array.", #15 "A project stage is missing its branch.", "A project stage is missing its script.", "A project as an invalid stage method.", "A key is missing its keyed package path.", "A key is missing its password.", #20 "A input mapping is invalid", "A key is missing from the keys section", "A project is missing its stage method.", #===============Warnings===============# "Using depricated files/folders projects keys. Use the combined source_files instead" #-1 ] end
has_stages(section_content:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 100 def has_stages(section_content:) section_content.class == Hash and section_content[:stages] end
process_errors(errors:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 177 def process_errors(errors:) errors.each do |error| @codes.push(error[0]) if error[1] end end
should_validate(key:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 83 def should_validate(key:) !([:default, :key_dir, :project_dir].include?(key)) end
singularize(section:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 95 def singularize(section:) section = section[0..-2] if section.end_with?("s") section.to_sym end
validate_config()
click to toggle source
# File lib/roku_builder/config_validator.rb, line 63 def validate_config @codes = [] validate_structure [:projects, :devices, :keys, :input_mappings].each do |section| validate_section(section: section) if @config[section] end @codes.uniq! @codes.push(VALID_CONFIG) if @codes.empty? end
validate_device(device:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 122 def validate_device(device:) errors = [ [DEVICE_MISSING_IP, (!device[:ip])], [DEVICE_MISSING_IP, (device[:ip] == "xxx.xxx.xxx.xxx")], [DEVICE_MISSING_IP, (device[:ip] == "")], [DEVICE_MISSING_USER, (!device[:user])], [DEVICE_MISSING_USER, (device[:user] == "<username>")], [DEVICE_MISSING_USER, (device[:user] == "")], [DEVICE_MISSING_PASSWORD, (!device[:password])], [DEVICE_MISSING_PASSWORD, (device[:password] == "<password>")], [DEVICE_MISSING_PASSWORD, (device[:password] == "")] ] process_errors(errors: errors) end
validate_input_mapping(input_mapping:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 170 def validate_input_mapping(input_mapping:) errors=[ [INVALID_MAPPING_INFO, (input_mapping.count != 2)] ] process_errors(errors: errors) end
validate_key(key:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 160 def validate_key(key:) errors= [ [KEY_MISSING_PATH, (!key[:keyed_pkg])], [KEY_MISSING_PATH, (key[:keyed_pkg] == "<path/to/signed/package>")], [KEY_MISSING_PASSWORD, (!key[:password])], [KEY_MISSING_PASSWORD, (key[:password] == "<password>")], ] process_errors(errors: errors) end
validate_project(project:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 137 def validate_project(project:) errors= [ [PROJECT_MISSING_APP_NAME, (!project[:app_name])], [PROJECT_MISSING_DIRECTORY, (!project[:directory])], [PROJECT_FOLDERS_BAD, (project[:folders] and !project[:folders].is_a?(Array))], [PROJECT_MISSING_FILES, (!project[:source_files] and !(project[:files] and project[:folders]))], [PROJECT_FILES_BAD, (project[:files] and !project[:files].is_a?(Array))], [MISSING_STAGE_METHOD, ( !project[:stage_method])], [PROJECT_STAGE_METHOD_BAD, (![:git, :script, :plugin, nil].include?(project[:stage_method]))], [PROJECT_MISSING_PLUGIN, (!project[:staging_plugin] and project[:stage_method] == :plugin)], [DEPRICATED_FILES_FOLDERS, (project[:files] or project[:folders])], ] process_errors(errors: errors) end
validate_section(section:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 73 def validate_section(section:) @config[section].each do |key, value| next unless should_validate(key: key) call_validate_method_for_section(section: section, content: value) if has_stages(section_content: value) validate_stages(project_content: value) end end end
validate_stage(stage:, project:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 152 def validate_stage(stage:, project:) errors= [ [STAGE_MISSING_BRANCH, (!stage[:branch] and project[:stage_method] == :git)], [STAGE_MISSING_SCRIPT, (!stage[:script] and project[:stage_method] == :script)], ] process_errors(errors: errors) end
validate_stages(project_content:)
click to toggle source
# File lib/roku_builder/config_validator.rb, line 104 def validate_stages(project_content:) project_content[:stages].each_value {|stage_config| validate_stage(stage: stage_config, project: project_content) } end
validate_structure()
click to toggle source
# File lib/roku_builder/config_validator.rb, line 111 def validate_structure errors = [ [MISSING_DEVICES, !@config[:devices]], [MISSING_DEVICES_DEFAULT, (@config[:devices] and !@config[:devices][:default])], [DEVICE_DEFAULT_BAD, (@config[:devices] and @config[:devices][:default] and !@config[:devices][:default].is_a?(Symbol))], [MISSING_PROJECTS_DEFAULT, (@config[:projects] and @config[:projects][:default] and @config[:projects][:default] == "<project id>".to_sym)], [PROJECTS_DEFAULT_BAD, (@config[:projects] and @config[:projects][:default] and !@config[:projects][:default].is_a?(Symbol))] ] process_errors(errors: errors) end