Class: Puppet::Pops::Loader::LoaderPaths::TaskPath

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

Overview

TaskPath is like PuppetSmartPath but it does not use an extension and may match more than one path with one name

Constant Summary collapse

TASKS_PATH =
'tasks'.freeze
FORBIDDEN_EXTENSIONS =
%w{.conf .md}.freeze

Constants inherited from PuppetSmartPath

PuppetSmartPath::EXTENSION

Instance Attribute Summary

Attributes inherited from SmartPath

#generic_path

Instance Method Summary collapse

Methods inherited from PuppetSmartPath

#effective_path

Methods inherited from SmartPath

#effective_path, #initialize, #lib_root?, #root_path

Constructor Details

This class inherits a constructor from Puppet::Pops::Loader::LoaderPaths::SmartPath

Instance Method Details

#extensionObject


240
241
242
# File 'lib/puppet/pops/loader/loader_paths.rb', line 240

def extension
  EMPTY_STRING
end

#fuzzy_matching?Boolean


244
245
246
# File 'lib/puppet/pops/loader/loader_paths.rb', line 244

def fuzzy_matching?
  true
end

#instantiatorObject


270
271
272
273
# File 'lib/puppet/pops/loader/loader_paths.rb', line 270

def instantiator
  require_relative 'task_instantiator'
  TaskInstantiator
end

#is_task_name?(name) ⇒ Boolean


284
285
286
# File 'lib/puppet/pops/loader/loader_paths.rb', line 284

def is_task_name?(name)
  !!(name =~ /^[a-z][a-z0-9_]*$/)
end

#relative_pathObject


248
249
250
# File 'lib/puppet/pops/loader/loader_paths.rb', line 248

def relative_path
  TASKS_PATH
end

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


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/puppet/pops/loader/loader_paths.rb', line 252

def typed_name(type, name_authority, relative_path, module_name)
  n = ''
  n << module_name unless module_name.nil?

  # Remove the file extension, defined as everything after the *last* dot.
  relative_path = relative_path.sub(%r{\.[^/.]*\z}, '')

  if relative_path == 'init' && !(module_name.nil? || module_name.empty?)
    TypedName.new(type, module_name, name_authority)
  else
    relative_path.split('/').each do |segment|
      n << '::' if n.size > 0
      n << segment
    end
    TypedName.new(type, n, name_authority)
  end
end

#valid_name?(typed_name) ⇒ Boolean


275
276
277
278
# File 'lib/puppet/pops/loader/loader_paths.rb', line 275

def valid_name?(typed_name)
  # TODO: Remove when PE has proper namespace handling
  typed_name.name_parts.size <= 2
end

#valid_path?(path) ⇒ Boolean


280
281
282
# File 'lib/puppet/pops/loader/loader_paths.rb', line 280

def valid_path?(path)
  path.start_with?(generic_path) && is_task_name?(File.basename(path, '.*')) && !FORBIDDEN_EXTENSIONS.any? { |ext| path.end_with?(ext) }
end