Module: IconGenerator::Validator

Included in:
Builder, FaviconBuilder, TouchBuilder
Defined in:
lib/icon_generator/validator.rb

Overview

Module intended to be used as a convenient mixin.

Examples:

Including the validator in a class

class Foo
    include IconGenerator::Validator
    # Now you can use validate_arguments and
    # validate_file_status as if they were your very own.
end

Instance Method Summary collapse

Instance Method Details

#validate_arguments(source, destination) ⇒ Object

Validates the given source image file and the destination directory for correctness.

Parameters:

  • source (String)

    the source image file

  • destination (String)

    the output directory

Raises:



16
17
18
19
20
# File 'lib/icon_generator/validator.rb', line 16

def validate_arguments(source, destination)
    raise IconGenerator::Error, '1st argument must be a valid image' unless source.match /\.gif$|\.jpg$|\.png$/
    raise IconGenerator::Error, '1st argument must be an existing file' unless File.exists? source
    raise IconGenerator::Error, '2nd argument must be an existing directory' unless Dir.exists? destination
end

#validate_file_status(filename) ⇒ Object

Validates the existence of the given file.

Parameters:

  • filename (String)

    the file being tested for existence

Raises:



25
26
27
# File 'lib/icon_generator/validator.rb', line 25

def validate_file_status(filename)
    raise IconGenerator::Error unless File.exists? filename
end