Class: PicsolveDockerBuilder::Builder::File

Inherits:
Object
  • Object
show all
Includes:
PicsolveDockerBuilder::Base
Defined in:
lib/picsolve_docker_builder/builder/file.rb

Overview

File helper to add files to tars

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PicsolveDockerBuilder::Base

#base_dir, #config, #config_file, #config_path, #config_paths, #create_logger, #default_config, #log, #read_config, #validate_config

Constructor Details

#initialize(path, opts = {}) ⇒ File

Returns a new instance of File.



9
10
11
12
# File 'lib/picsolve_docker_builder/builder/file.rb', line 9

def initialize(path, opts = {})
  @opts = opts
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/picsolve_docker_builder/builder/file.rb', line 8

def path
  @path
end

Instance Method Details

#add_to_image?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/picsolve_docker_builder/builder/file.rb', line 26

def add_to_image?
  @opts.key? :destination
end

#add_to_tar(tar) ⇒ Object



38
39
40
41
42
43
# File 'lib/picsolve_docker_builder/builder/file.rb', line 38

def add_to_tar(tar)
  log.debug "add file from #{source} to #{path} in tar"
  tar.add_file path, mode do |tf|
    ::File.open(source, 'rb') { |f| tf.write f.read }
  end
end

#contentObject



14
15
16
17
18
19
20
# File 'lib/picsolve_docker_builder/builder/file.rb', line 14

def content
  return @opts[:content] if @opts.key? :content

  return read_source if @opts.key? :source

  fail 'No content found'
end

#destinationObject



22
23
24
# File 'lib/picsolve_docker_builder/builder/file.rb', line 22

def destination
  @opts[:destination]
end

#modeObject



34
35
36
# File 'lib/picsolve_docker_builder/builder/file.rb', line 34

def mode
  ::File.stat(source).mode
end

#sourceObject



30
31
32
# File 'lib/picsolve_docker_builder/builder/file.rb', line 30

def source
  @opts[:source]
end