Class: Imagemaster3000::Actions::Link

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target: nil, link: nil, symbolic: false) ⇒ Link

Returns a new instance of Link.



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

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

  @target = target
  @link = link
  @symbolic = symbolic
  logger.debug "Created action #{inspect}"
end

Instance Attribute Details

Returns the value of attribute link.



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

def link
  @link
end

#symbolicObject

Returns the value of attribute symbolic.



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

def symbolic
  @symbolic
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

Instance Method Details

#ln(image_file) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/imagemaster3000/actions/link.rb', line 22

def ln(image_file)
  ln_command = symbolic ? 'ln-s' : 'ln'

  Imagemaster3000::Utils::CommandExecutioner.execute Imagemaster3000::Settings[:'binaries-guestfish'],
                                                     '-a',
                                                     image_file,
                                                     '-i',
                                                     ln_command,
                                                     target,
                                                     link
end

#run(image_file) ⇒ Object



15
16
17
18
19
20
# File 'lib/imagemaster3000/actions/link.rb', line 15

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