Class: Puppet::Pops::Loader::LoaderPaths::PlanPath

Inherits:
PuppetSmartPath show all
Defined in:
lib/puppet/pops/loader/loader_paths.rb

Constant Summary collapse

PLAN_PATH =
File.join('plans')
PP_EXT =
'.pp'
YAML_EXT =
'.yaml'

Constants inherited from PuppetSmartPath

Puppet::Pops::Loader::LoaderPaths::PuppetSmartPath::EXTENSION

Instance Method Summary collapse

Methods inherited from SmartPath

#generic_path, #lib_root?, #root_path, #valid_name?

Constructor Details

#initialize(loader) ⇒ PlanPath

Returns a new instance of PlanPath.



319
320
321
322
323
324
325
326
327
328
# File 'lib/puppet/pops/loader/loader_paths.rb', line 319

def initialize(loader)
  super

  if Puppet.lookup(:yaml_plan_instantiator) { nil }
    @extensions = [PP_EXT, YAML_EXT]
  else
    @extensions = [PP_EXT]
  end
  @init_filenames = @extensions.map { |ext| "init#{ext}" }
end

Instance Method Details

#effective_path(typed_name, start_index_in_name) ⇒ Object



367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/puppet/pops/loader/loader_paths.rb', line 367

def effective_path(typed_name, start_index_in_name)
  # Puppet name to path always skips the name-space as that is part of the generic path
  # i.e. <module>/mymodule/functions/foo.pp is the function mymodule::foo
  parts = typed_name.name_parts
  if start_index_in_name > 0
    return nil if start_index_in_name >= parts.size

    parts = parts[start_index_in_name..]
  end
  basename = File.join(generic_path, parts)
  @extensions.map { |ext| "#{basename}#{ext}" }
end

#extensionObject



330
331
332
# File 'lib/puppet/pops/loader/loader_paths.rb', line 330

def extension
  EMPTY_STRING
end

#fuzzy_matching?Boolean

Returns:

  • (Boolean)


342
343
344
# File 'lib/puppet/pops/loader/loader_paths.rb', line 342

def fuzzy_matching?
  true
end

#instantiatorObject



338
339
340
# File 'lib/puppet/pops/loader/loader_paths.rb', line 338

def instantiator
  Puppet::Pops::Loader::GenericPlanInstantiator
end

#relative_pathObject



334
335
336
# File 'lib/puppet/pops/loader/loader_paths.rb', line 334

def relative_path
  PLAN_PATH
end

#typed_name(type, name_authority, relative_path, module_name) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/puppet/pops/loader/loader_paths.rb', line 350

def typed_name(type, name_authority, relative_path, module_name)
  if @init_filenames.include?(relative_path) && !(module_name.nil? || module_name.empty?)
    TypedName.new(type, module_name, name_authority)
  else
    n = ''.dup
    n << module_name unless module_name.nil?
    ext = @extensions.find { |extension| relative_path.end_with?(extension) }
    relative_path = relative_path[0..-(ext.length + 1)]

    relative_path.split('/').each do |segment|
      n << '::' if n.size > 0
      n << segment
    end
    TypedName.new(type, n, name_authority)
  end
end

#valid_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


346
347
348
# File 'lib/puppet/pops/loader/loader_paths.rb', line 346

def valid_path?(path)
  @extensions.any? { |ext| path.end_with?(ext) } && path.start_with?(generic_path)
end