Class: BoringBuilder::Artifact

Inherits:
Object
  • Object
show all
Defined in:
lib/boringbuilder/artifact.rb

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd) ⇒ Artifact

Returns a new instance of Artifact.



15
16
17
18
# File 'lib/boringbuilder/artifact.rb', line 15

def initialize(root: Dir.pwd)
  @root = Pathname.new(root).expand_path
  @entries = []
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



13
14
15
# File 'lib/boringbuilder/artifact.rb', line 13

def entries
  @entries
end

#rootObject (readonly)

Returns the value of attribute root.



13
14
15
# File 'lib/boringbuilder/artifact.rb', line 13

def root
  @root
end

Instance Method Details

#directory(source, at: source) ⇒ Object



20
21
22
# File 'lib/boringbuilder/artifact.rb', line 20

def directory(source, at: source)
  add(:container, :directory, source, at)
end

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/boringbuilder/artifact.rb', line 36

def empty?
  entries.empty?
end

#export_directory(client, container) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/boringbuilder/artifact.rb', line 45

def export_directory(client, container)
  return container.directory("/") if full_container_root?

  entries.reduce(client.directory) do |directory, entry|
    destination = entry.destination.delete_prefix("/")
    source = source_for(entry, client, container)

    if entry.kind == :file
      directory.with_file(destination, source)
    else
      directory.with_directory(destination, source)
    end
  end
end

#file(source, at: source) ⇒ Object



24
25
26
# File 'lib/boringbuilder/artifact.rb', line 24

def file(source, at: source)
  add(:container, :file, source, at)
end

#full_container_root?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/boringbuilder/artifact.rb', line 40

def full_container_root?
  entries.one? && entries.first.origin == :container && entries.first.kind == :directory &&
    entries.first.source == "/" && entries.first.destination == "/"
end

#host_path(source, at:) ⇒ Object

Raises:



28
29
30
31
32
33
34
# File 'lib/boringbuilder/artifact.rb', line 28

def host_path(source, at:)
  path = Pathname.new(source).expand_path(root)
  kind = path.file? ? :file : :directory
  raise ConfigurationError, "Host artifact path does not exist: #{path}" unless path.exist?

  add(:host, kind, path, at)
end

#to_aObject



60
61
62
# File 'lib/boringbuilder/artifact.rb', line 60

def to_a
  entries.map(&:to_h)
end