Class: Dapp::Build::Stage::Base

Inherits:
Object
  • Object
show all
Includes:
Mod::Logging, Helper::Sha256, Helper::Trivia
Defined in:
lib/dapp/build/stage/base.rb

Overview

Base of all stages

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mod::Logging

#ignore_log_commands?, #image_info, #log_build, #log_image_commands, #log_image_info, #should_be_introspected?, #should_be_not_detailed?, #should_be_not_present?, #should_be_skipped?, #size_difference?

Methods included from Helper::Trivia

class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs

Methods included from Helper::Sha256

#hashsum, #paths_content_hashsum, #sha256

Constructor Details

#initialize(application, next_stage) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
# File 'lib/dapp/build/stage/base.rb', line 13

def initialize(application, next_stage)
  @application = application

  @next_stage = next_stage
  @next_stage.prev_stage = self
end

Instance Attribute Details

#application ⇒ Object (readonly)

Returns the value of attribute application.



11
12
13
# File 'lib/dapp/build/stage/base.rb', line 11

def application
  @application
end

#next_stage ⇒ Object

Returns the value of attribute next_stage.



10
11
12
# File 'lib/dapp/build/stage/base.rb', line 10

def next_stage
  @next_stage
end

#prev_stage ⇒ Object

Returns the value of attribute prev_stage.



10
11
12
# File 'lib/dapp/build/stage/base.rb', line 10

def prev_stage
  @prev_stage
end

Instance Method Details

#build! ⇒ Object



20
21
22
23
24
25
# File 'lib/dapp/build/stage/base.rb', line 20

def build!
  return if should_be_skipped?
  prev_stage.build! if prev_stage
  image_build unless empty? && !application.log_verbose?
  raise Exception::IntrospectImage, data: { built_id: image.built_id, options: image.send(:prepared_options) } if should_be_introspected?
end

#dependencies ⇒ Object



62
63
64
# File 'lib/dapp/build/stage/base.rb', line 62

def dependencies
  []
end

#dependencies_empty? ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/dapp/build/stage/base.rb', line 50

def dependencies_empty?
  dependencies.flatten.compact.delete_if { |val| val.respond_to?(:empty?) && val.empty? }.empty?
end

#empty? ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dapp/build/stage/base.rb', line 46

def empty?
  dependencies_empty?
end

#image ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dapp/build/stage/base.rb', line 33

def image
  @image ||= begin
    if empty?
      prev_stage.image
    else
      Image::Stage.new(name: image_name, from: from_image).tap do |image|
        image.add_change_label dapp: application.config._basename
        yield image if block_given?
      end
    end
  end
end

#save_in_cache! ⇒ Object



27
28
29
30
31
# File 'lib/dapp/build/stage/base.rb', line 27

def save_in_cache!
  prev_stage.save_in_cache! if prev_stage
  return unless should_be_tagged?
  image.tag!(log_verbose: application.log_verbose?, log_time: application.log_time?) unless application.dry_run?
end

#signature ⇒ Object



54
55
56
57
58
59
60
# File 'lib/dapp/build/stage/base.rb', line 54

def signature
  if empty?
    prev_stage.signature
  else
    hashsum [prev_stage.signature, *dependencies.flatten]
  end
end