Class: Bosh::Cli::ArchiveBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/archive_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive_repository_provider, options = {}) ⇒ ArchiveBuilder

Returns a new instance of ArchiveBuilder.



5
6
7
8
# File 'lib/cli/archive_builder.rb', line 5

def initialize(archive_repository_provider, options = {})
  @archive_repository_provider = archive_repository_provider
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/cli/archive_builder.rb', line 3

def options
  @options
end

Instance Method Details

#build(resource) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cli/archive_builder.rb', line 10

def build(resource)
  @archive_repository = @archive_repository_provider.get(resource)
  resource.run_script(:prepare)

  artifact = nil
  with_indent('  ') do
    artifact = locate_artifact(resource)
    if artifact.nil?
      artifact = create_artifact(resource)
      say("Generated version '#{artifact.fingerprint}'".make_green)

      unless dry_run?
        artifact = @archive_repository.install(artifact)
      end
    end

    if final? && !dry_run?
      say("Uploading final version '#{artifact.version}'...")
      artifact, blobstore_id = @archive_repository.upload_to_blobstore(artifact)
      say("Uploaded, blobstore id '#{blobstore_id}'")
    end
  end

  artifact
rescue Bosh::Blobstore::BlobstoreError => e
  raise BlobstoreError, "Blobstore error: #{e}"
end

#dry_run?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/cli/archive_builder.rb', line 38

def dry_run?
  !!options[:dry_run]
end

#final?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/cli/archive_builder.rb', line 42

def final?
  !!options[:final]
end