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'
FORBIDDEN_EXTENSIONS =
%w[.conf .md].freeze

Constants inherited from PuppetSmartPath

PuppetSmartPath::EXTENSION

Instance Method Summary collapse

Methods inherited from PuppetSmartPath

#effective_path

Methods inherited from SmartPath

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

Constructor Details

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

Instance Method Details

#extensionObject



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

def extension
  EMPTY_STRING
end

#fuzzy_matching?Boolean

Returns:

  • (Boolean)


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

def fuzzy_matching?
  true
end

#instantiatorObject



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

def instantiator
  require_relative 'task_instantiator'
  TaskInstantiator
end

#is_task_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#relative_pathObject



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

def relative_path
  TASKS_PATH
end

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



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

def typed_name(type, name_authority, relative_path, module_name)
  n = ''.dup
  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

Returns:

  • (Boolean)


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

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

#valid_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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