module ArmaFixer::Validation

Public Instance Methods

default_image() click to toggle source
# File lib/arma_fixer/validation.rb, line 60
def default_image
  ArmaFixer::DEFAULT_IMAGE_PATH if default_image_path_defined?
end
default_image_path_defined?() click to toggle source
# File lib/arma_fixer/validation.rb, line 64
def default_image_path_defined?
  defined?(ArmaFixer::DEFAULT_IMAGE_PATH)
end
run!() click to toggle source
# File lib/arma_fixer/validation.rb, line 7
def run!
  validate_models_hash!
  validate_default_image_path!
  validate_attribute_checker!
end
validate_attribute_checker!() click to toggle source
# File lib/arma_fixer/validation.rb, line 68
def validate_attribute_checker!
  if defined?(ArmaFixer::ATTR_CHECKER)
    unless ArmaFixer::ATTR_CHECKER.is_a?(Proc)
      fail 'ArmaFixer::ATTR_CHECKER must be a lambda'
    end
  end
end
validate_default_image_path!() click to toggle source
# File lib/arma_fixer/validation.rb, line 53
def validate_default_image_path!
  return unless default_image_path_defined?
  path = ArmaFixer::DEFAULT_IMAGE_PATH
  fail 'ArmaFixer::DEFAULT_IMAGE_PATH must be a string' unless path.is_a?(String)
  fail "file not found at '#{path}'" unless File.exist?(path)
end
validate_models_hash!() click to toggle source
# File lib/arma_fixer/validation.rb, line 17
def validate_models_hash!
  validate_models_hash_presence!
  validate_models_hash_contents!
end
validate_models_hash_contents!() click to toggle source
# File lib/arma_fixer/validation.rb, line 30
def validate_models_hash_contents!
  ArmaFixer::MODELS_HASH.each_value do |attributes|
    case attributes
    when Array
      if attributes.empty?
        fail 'attributes array cannot be empty'
      elsif !default_image_path_defined?
        fail 'ArmaFixer::DEFAULT_IMAGE_PATH must exist in case of array attributes'
      end
    when Hash
      if attributes.empty?
        fail 'attributes hash cannot be empty'
      else
        attributes.each_value do |path|
          fail "file not found at #{path}" unless File.exist?(path)
        end
      end
    else
      fail 'attributes must be in form of hash or array'
    end
  end
end
validate_models_hash_presence!() click to toggle source
# File lib/arma_fixer/validation.rb, line 22
def validate_models_hash_presence!
  return if defined?(ArmaFixer::MODELS_HASH) &&
            ArmaFixer::MODELS_HASH &&
            !ArmaFixer::MODELS_HASH.empty?

  fail 'ArmaFixer::MODELS_HASH cannot be undefined or empty.'
end