Module: PDK::Context

Defined in:
lib/pdk/context.rb,
lib/pdk/context/none.rb,
lib/pdk/context/module.rb,
lib/pdk/context/control_repo.rb

Defined Under Namespace

Classes: AbstractContext, ControlRepo, Module, None

Class Method Summary collapse

Class Method Details

.create(context_path) ⇒ PDK::Context::AbstractContext

Automatically determines the PDK Context given a path. Create will continue up the directory tree until it finds a valid context

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pdk/context.rb', line 12

def self.create(context_path)
  return PDK::Context::None.new(context_path) unless PDK::Util::Filesystem.directory?(context_path)

  previous = nil
  current = PDK::Util::Filesystem.expand_path(context_path)
  until !PDK::Util::Filesystem.directory?(current) || current == previous
    # Control Repo detection
    return PDK::Context::ControlRepo.new(current, context_path) if PDK.feature_flag?('controlrepo') && PDK::ControlRepo.control_repo_root?(current)

    # Puppet Module detection
     = File.join(current, 'metadata.json')
    return PDK::Context::Module.new(current, context_path) if PDK::Util::Filesystem.file?() || PDK::Util.in_module_root?(context_path)

    previous = current
    current = PDK::Util::Filesystem.expand_path('..', current)
  end
  PDK::Context::None.new(context_path)
end