Class: BuildpackSupport::Component::BaseDroplet

Inherits:
Object
  • Object
show all
Extended by:
DirectoryFinder
Defined in:
lib/buildpack_support/component/base_droplet.rb

Overview

An abstraction around the droplet that will be created and used at runtime. This abstraction is intended to hide the work done by components within their own sandboxes, while exposing changes made to the user’s application. Think of this as a mutable representation of a component’s sandbox and the application that was uploaded.

A new instance of this type should be created for each component.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DirectoryFinder

load_path_peer

Constructor Details

#initialize(component_id, root) ⇒ BaseDroplet

Creates a new instance of the droplet abstraction

Parameters:

  • component_id (String)

    the id of the component that will use this Droplet

  • root (Pathname)

    the root of the droplet



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/buildpack_support/component/base_droplet.rb', line 51

def initialize(component_id, root)
  @component_id = component_id
  @logger       = BuildpackSupport::Logging::LoggerFactory.instance.get_logger self.class

  buildpack_root = root + '.buildpack'
  sandbox_root   = buildpack_root + component_id

  @sandbox = BuildpackSupport::FilteringPathname.new(sandbox_root, ->(path) { in?(path, sandbox_root) }, true)
  @root    = BuildpackSupport::FilteringPathname.new(root,
                                                     ->(path) { !in?(path, buildpack_root) || in?(path, @sandbox) },
                                                     true)
end

Instance Attribute Details

#component_idString (readonly)

Returns the id of component using this droplet.

Returns:

  • (String)

    the id of component using this droplet



36
37
38
# File 'lib/buildpack_support/component/base_droplet.rb', line 36

def component_id
  @component_id
end

#rootBuildpackSupport::FilteringPathname (readonly)

Returns the root of the droplet’s fileystem filtered so that it excludes files in the sandboxes of other components.

Returns:



41
42
43
# File 'lib/buildpack_support/component/base_droplet.rb', line 41

def root
  @root
end

#sandboxPathname (readonly)

Returns the root of the component’s sandbox.

Returns:

  • (Pathname)

    the root of the component’s sandbox



45
46
47
# File 'lib/buildpack_support/component/base_droplet.rb', line 45

def sandbox
  @sandbox
end

Instance Method Details

#copy_resources(target_directory = @sandbox) ⇒ Void

Copy resources from a components resources directory to a directory

Parameters:

  • target_directory (Pathname) (defaults to: @sandbox)

    the directory to copy to. Defaults to the component’s sandbox.

Returns:

  • (Void)


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/buildpack_support/component/base_droplet.rb', line 68

def copy_resources(target_directory = @sandbox)
  resources = RESOURCES_DIRECTORY + @component_id

  if resources.exist?
    FileUtils.mkdir_p target_directory
    FileUtils.cp_r("#{resources}/.", target_directory)
    @logger.debug { "Resources #{resources} found" }
  else
    @logger.debug { "No resources #{resources} found" }
  end
end