module TiendappValidator

TiendApp Validator

TiendApp Validator - Auxiliar Methods

TiendApp Validator I18n configurations

Liquid_validators - containe liquid validation methods

TiendApp Validator - Methods to validate customization schema

Constants

CHECKOUT_PATH

Paths basicos de los archivos necesarios

DEFAULT_LANGUAGE
EXTENSIONS

Format list

LIQUID_FILES

Nombre de los archivos necesarios de la aplicacion

LIQUID_FILES_CHECKOUT

Subcarpeta checkout

LIQUID_FILES_MAILER

Subcarpeta mailer

MAILER_PATH
SCHEMA_FILES

Schema files

VALIDATION_METHODS
VERSION

Public Class Methods

customization_schemas() click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 17
def self.customization_schemas
  @customization_schemas ||= get_files(root_path + 'config/', 'json')
end
define_language(id) click to toggle source
# File lib/tiendapp_validator/i18n.rb, line 14
def self.define_language(id)
  if id == 'es'
    I18n.locale = :es
  elsif id == 'en'
    I18n.locale = :en
  end
end
exist_liquid_file(str) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 58
def self.exist_liquid_file(str)
  path = root_path
  while str.include? '/'
    substring = str.split('/')[0]
    str = str.split('/')[1]
    path = path + substring + '/'
  end
  path + '_' + str + '.liquid'
end
get_content(path) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 29
def self.get_content(path)
  file = File.open(path)
  file.read
end
get_files(path, extension) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 21
def self.get_files(path, extension)
  file_paths = []
  Find.find(path) do |p|
    file_paths << p if p =~ /\.(?:#{extension})$/i && !p.include?('/.git/')
  end
  file_paths
end
get_format(file) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 39
def self.get_format(file)
  expr = /\.(\w*)$/
  expr.match(file)[1]
end
get_includes(content) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 34
def self.get_includes(content)
  expr = /\{\%\s+include\s+[",'](.*)[",']\s+\%\}/
  content.scan(expr)
end
liquid_files() click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 13
def self.liquid_files
  @liquid_files ||= get_files(root_path, 'liquid')
end
permit_extension?(file) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 44
def self.permit_extension?(file)
  extension = get_format(file)
  EXTENSIONS.include? extension
end
print_response(res) click to toggle source
response(status, message, valid) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 68
def self.response(status, message, valid)
  { status: status,
    message: message,
    valid: valid }
end
root_path(path = nil) click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 3
def self.root_path(path = nil)
  if path.nil?
    @root_path
  else
    @liquid_files = nil
    @customization_schemas = nil
    @root_path = path
  end
end
validate(path) click to toggle source
# File lib/tiendapp_validator.rb, line 19
def self.validate(path)
  root_path(path)
  VALIDATION_METHODS.each do |method|
    res = method.call
    next if res[:valid]
    return res
  end
  response 'OK', I18n.t('ok.all_validation'), true
end
validate_customation_schema_file() click to toggle source

VG001 - Validar syntaxis customization schema

# File lib/tiendapp_validator/schema_validators.rb, line 4
def self.validate_customation_schema_file
  SCHEMA_FILES.each do |schema|
    next if customization_schemas.include? root_path + 'config/' + schema
    return response 'Error', I18n.t('error.customization_schema_not_found', schema: schema) , false
  end
  response 'OK', I18n.t('ok.found_all_customization_schema_files'), true
end
validate_extensions() click to toggle source
# File lib/tiendapp_validator/auxiliar_methods.rb, line 49
def self.validate_extensions
  Find.find(root_path) do |p|
    next unless p.include? '.'
    next if permit_extension? p
    return response 'ERROR', I18n.t('error.not_support_extension', extension: p.split(root_path)[1]), false
  end
  response 'OK', I18n.t('ok.all_support_format'), true
end
validate_folders_liquid_files() click to toggle source

VL003 - Validar si todas las llamadas a vistas parciales existen

# File lib/tiendapp_validator/liquid_validators.rb, line 28
def self.validate_folders_liquid_files
  path = root_path
  (LIQUID_FILES_CHECKOUT + LIQUID_FILES_MAILER).each do |liquid|
    next if liquid_files.include? path + CHECKOUT_PATH + liquid
    next if liquid_files.include? path + MAILER_PATH + liquid
    return response 'error', I18n.t('error.file_not_found', liquid: liquid), false
  end
  response 'OK', I18n.t('ok.found_checkout_liquid_files'), true
end
validate_include_liquid_files() click to toggle source

VL004 - Validar si todas las llamadas a vistas parciales existen

# File lib/tiendapp_validator/liquid_validators.rb, line 39
def self.validate_include_liquid_files
  liquid_files.each do |liquid|
    content = get_content(liquid)
    includes = get_includes(content)
    includes.each do |include|
      unless exist_liquid_file(include[0])
        return response 'error', I18n.t('error.include_not_found', include: include[0]), false
      end
    end
  end
  response 'OK', I18n.t('ok.all_include_exists'), true
end
validate_liquid_files() click to toggle source

VL001 - Validar presencia de los archivos liquid

# File lib/tiendapp_validator/liquid_validators.rb, line 6
def self.validate_liquid_files
  LIQUID_FILES.each do |liquid|
    next if liquid_files.include? root_path + liquid
    return response 'error', I18n.t('error.file_not_found', liquid: liquid), false
  end
  response 'OK', I18n.t('ok.found_all_liquid_files'), true
end
validate_liquid_files_syntax() click to toggle source

VL006 - Valida que los archivos tengan sintaxis correcta en Liquid

# File lib/tiendapp_validator/liquid_validators.rb, line 53
def self.validate_liquid_files_syntax
  file_paths = get_files root_path, 'liquid'
  file_paths.each do |liquid|
    next if Liquid::Template.parse(get_content(liquid), error_mode: :strict)
    return response 'error', I18n.t(error.syntax_error, liquid: liquid.split(root_path)[0]), false
  end
  response 'OK', I18n.t('ok.liquid_files_syntax'), true
end
validate_partial_liquid_files() click to toggle source

VL002 - Validar vistas parciales liquid

# File lib/tiendapp_validator/liquid_validators.rb, line 15
def self.validate_partial_liquid_files
  file_paths = get_files root_path, 'liquid'
  file_paths.each do |liquid|
    liquid = liquid.split('/').last
    next if LIQUID_FILES.include? liquid
    next if liquid[0] == '_'
    next if (LIQUID_FILES_CHECKOUT + LIQUID_FILES_MAILER).include? liquid
    return response 'error', I18n.t('error.name_invalid', liquid: liquid), false
  end
  response 'OK', I18n.t('ok.partial_liquid_files'), true
end