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'.freeze
YAML_EXT =
'.yaml'.freeze

Constants inherited from PuppetSmartPath

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

Instance Attribute Summary

Attributes inherited from SmartPath

#generic_path

Instance Method Summary collapse

Methods inherited from SmartPath

#lib_root?, #root_path, #valid_name?

Constructor Details

#initialize(loader) ⇒ PlanPath

Returns a new instance of PlanPath


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

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


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

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..-1]
  end
  basename = File.join(generic_path, parts)
  @extensions.map { |ext| "#{basename}#{ext}" }
end

#extensionObject


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

def extension
  EMPTY_STRING
end

#fuzzy_matching?Boolean


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

def fuzzy_matching?
  true
end

#instantiatorObject


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

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

#relative_pathObject


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

def relative_path
  PLAN_PATH
end

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


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

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 = ''
    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


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

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