Class: SimpleImagesDownloader::Dispenser

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Validatable
Defined in:
lib/simple_images_downloader/dispenser.rb

Overview

Dispenser class Responsible for moving tempfile to destination directory

Examples:

SimpleImagesDownloader::Dispenser.new(tempfile, 'https://example.com/image.jpg').place

Instance Method Summary collapse

Methods included from Validatable

#validate!

Constructor Details

#initialize(source, remote_path, validators = [DestinationValidator.new]) ⇒ Dispenser

Default: [DestinationValidator.new]

Parameters:

  • source (Tempfile)

    Tempfile object

  • remote_path (String)

    original path of the image from input of SimpleImagesDownloader module

  • validators (Array) (defaults to: [DestinationValidator.new])

    array of validators for validating the destination directory.



20
21
22
23
24
# File 'lib/simple_images_downloader/dispenser.rb', line 20

def initialize(source, remote_path, validators = [DestinationValidator.new])
  @source      = source
  @remote_path = remote_path
  @validators  = validators
end

Instance Method Details

#placeObject

Moves tempfile to destination directory

Raises:

  • (Errors::BadDestination)

    if destination directory is not valid

See Also:



30
31
32
33
34
# File 'lib/simple_images_downloader/dispenser.rb', line 30

def place
  validate!({ path: destination_dir })

  FileUtils.mv @source, target
end