Class: Imagemaster3000::Actions::Copy

Inherits:
Object
  • Object
show all
Defined in:
lib/imagemaster3000/actions/copy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source: nil, target: nil, name: nil) ⇒ Copy

Returns a new instance of Copy.



6
7
8
9
10
11
12
13
14
# File 'lib/imagemaster3000/actions/copy.rb', line 6

def initialize(source: nil, target: nil, name: nil)
  raise Imagemaster3000::Errors::ArgumentError, 'neither source nor target can be nil' if source.empty? || target.empty?

  @filename = source
  @source = File.join(Imagemaster3000::Settings[:'definitions-dir'], 'files', source)
  @target = target
  @name = name
  logger.debug "Created action #{inspect}"
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



4
5
6
# File 'lib/imagemaster3000/actions/copy.rb', line 4

def filename
  @filename
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/imagemaster3000/actions/copy.rb', line 4

def name
  @name
end

#sourceObject

Returns the value of attribute source.



4
5
6
# File 'lib/imagemaster3000/actions/copy.rb', line 4

def source
  @source
end

#targetObject

Returns the value of attribute target.



4
5
6
# File 'lib/imagemaster3000/actions/copy.rb', line 4

def target
  @target
end

Instance Method Details

#run(image_file) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/imagemaster3000/actions/copy.rb', line 16

def run(image_file)
  logger.debug "Running 'copy' action with source #{source.inspect} and target #{target.inspect} on file #{image_file.inspect}"
  copy image_file
  rename image_file if name
rescue Imagemaster3000::Errors::CommandExecutionError => ex
  raise Imagemaster3000::Errors::ActionError, ex
end