Class: IML::FileMover

Inherits:
Object
  • Object
show all
Defined in:
lib/iml/file_mover.rb

Instance Method Summary collapse

Constructor Details

#initialize(formatter: IML::Formatter.new) ⇒ FileMover

Returns a new instance of FileMover.



4
5
6
# File 'lib/iml/file_mover.rb', line 4

def initialize(formatter: IML::Formatter.new)
  @formatter = formatter
end

Instance Method Details

#call(source_path, media, format: nil, target: nil, pretend: false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/iml/file_mover.rb', line 8

def call(source_path, media, format: nil, target: nil, pretend: false)
  dest = @formatter.pathname(media, format: format, target: target)

  unless pretend
    FileUtils.mkdir_p(dest.dirname)
    FileUtils.mv(source_path.to_s, dest.to_s)
  end

  dest
rescue Errno::ENOENT => e
  raise IML::FileNotFoundError, e.message
end