class Nabokov::NabokovfileContentValidator

This class is responsible for nabokovfile content validation The validation rules are for localizations_repo and project_repo settings

Attributes

nabokovfile_hash[RW]

Public Class Methods

new(nabokovfile_hash) click to toggle source
# File lib/nabokov/core/nabokovfile_content_validator.rb, line 10
def initialize(nabokovfile_hash)
  self.nabokovfile_hash = nabokovfile_hash
end

Public Instance Methods

validate() click to toggle source

Performs validation First rule: localizations_repo should be the type of Hash

localizations_repo_url should be valid URL with secure https scheme

Second rule: project_repo should be the type of Hash

project localizations_key should be the of Hash
project_localization_file_paths should point to existed files
project_local_path should point to valid folder
# File lib/nabokov/core/nabokovfile_content_validator.rb, line 21
def validate
  validate_localizations_repo
  validate_project_repo
end

Private Instance Methods

validate_localizations_repo() click to toggle source
# File lib/nabokov/core/nabokovfile_content_validator.rb, line 28
def validate_localizations_repo
  localizations_repo = self.nabokovfile_hash[NabokovfileKeyes.localizations_repo]
  raise "Localizations repo must be a type of Hash" unless localizations_repo.kind_of?(Hash)

  url = localizations_repo[NabokovfileKeyes.localizations_repo_url]
  raise "'#{url}' is not a valid URL" unless url =~ URI.regexp
  raise "Please use 'https://...' instead of '#{url}' only supports encrypted requests" unless url.start_with?("https://")
end
validate_project_repo() click to toggle source
# File lib/nabokov/core/nabokovfile_content_validator.rb, line 37
def validate_project_repo
  project_repo = self.nabokovfile_hash[NabokovfileKeyes.project_repo]
  raise "Project repo must be a type of Hash" unless project_repo.kind_of?(Hash)

  localizations_key = NabokovfileKeyes.project_localization_file_paths
  localizations = project_repo[localizations_key]
  raise "Localizations must be a type of Hash" unless localizations.kind_of?(Hash)
  localizations.each_value { |path| raise "Couldn't find strings file at '#{path}'" unless File.exist?(path) }

  project_local_path_key = NabokovfileKeyes.project_local_path
  project_local_path = project_repo[project_local_path_key]
  raise "Project repo local path must be presented" if project_local_path.nil?
end