Class: Puppet::Pops::Loader::LoaderPaths::SmartPath

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

Overview

# DO NOT REMOVE YET. needed later? when there is the need to decamel a classname

def de_camel(fq_name)
  fq_name.to_s.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end

Direct Known Subclasses

PuppetSmartPath, RubySmartPath

Instance Method Summary collapse

Constructor Details

#initialize(loader) ⇒ SmartPath

Creates SmartPath for the given loader (loader knows how to check for existence etc.)



58
59
60
# File 'lib/puppet/pops/loader/loader_paths.rb', line 58

def initialize(loader)
  @loader = loader
end

Instance Method Details

#effective_path(typed_name, start_index_in_name) ⇒ Object

Effective path is the generic path + the name part(s) + extension.



84
85
86
# File 'lib/puppet/pops/loader/loader_paths.rb', line 84

def effective_path(typed_name, start_index_in_name)
  "#{File.join(generic_path, typed_name.name_parts)}#{extension}"
end

#fuzzy_matching?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/puppet/pops/loader/loader_paths.rb', line 70

def fuzzy_matching?
  false
end

#generic_pathObject

Generic path, in the sense of “if there are any entities of this kind to load, where are they?”



63
64
65
66
67
68
# File 'lib/puppet/pops/loader/loader_paths.rb', line 63

def generic_path
  return @generic_path unless @generic_path.nil?

  the_root_path = root_path # @loader.path
  @generic_path = (the_root_path.nil? ? relative_path : File.join(the_root_path, relative_path))
end

#instantiatorObject

Raises:

  • (NotImplementedError)


114
115
116
# File 'lib/puppet/pops/loader/loader_paths.rb', line 114

def instantiator
  raise NotImplementedError
end

#lib_root?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/puppet/pops/loader/loader_paths.rb', line 78

def lib_root?
  @loader.lib_root?
end

#relative_pathObject

Raises:

  • (NotImplementedError)


110
111
112
# File 'lib/puppet/pops/loader/loader_paths.rb', line 110

def relative_path
  raise NotImplementedError
end

#root_pathObject



74
75
76
# File 'lib/puppet/pops/loader/loader_paths.rb', line 74

def root_path
  @loader.path
end

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



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/puppet/pops/loader/loader_paths.rb', line 88

def typed_name(type, name_authority, relative_path, module_name)
  # Module name is assumed to be included in the path and therefore not added here
  n = ''.dup
  unless extension.empty?
    # Remove extension
    relative_path = relative_path[0..-(extension.length + 1)]
  end
  relative_path.split('/').each do |segment|
    n << '::' if n.size > 0
    n << segment
  end
  TypedName.new(type, n, name_authority)
end

#valid_name?(typed_name) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/puppet/pops/loader/loader_paths.rb', line 106

def valid_name?(typed_name)
  true
end

#valid_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/puppet/pops/loader/loader_paths.rb', line 102

def valid_path?(path)
  path.end_with?(extension) && path.start_with?(generic_path)
end