Class: Puppet::Pops::Binder::SchemeHandler::ModuleScheme

Inherits:
SymbolicScheme show all
Defined in:
lib/puppet/pops/binder/scheme_handler/module_scheme.rb

Constant Summary collapse

METADATA_DATA_PROVIDER =
'data_provider'.freeze

Instance Method Summary collapse

Methods inherited from SymbolicScheme

#fqn_from_path, #has_wildcard?, #is_optional?

Methods inherited from Puppet::Plugins::BindingSchemes::BindingsSchemeHandler

#is_optional?

Instance Method Details

#contributed_bindings(uri, scope, composer) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/puppet/pops/binder/scheme_handler/module_scheme.rb', line 23

def contributed_bindings(uri, scope, composer)
  split_name, fqn = fqn_from_path(uri)
  bindings = Puppet::Bindings.resolve(scope, split_name[0]) || load_bindings(uri, scope, composer, split_name, fqn)

  # Must clone as the rest mutates the model
  BindingsFactory.contributed_bindings(fqn, Marshal.load(Marshal.dump(bindings)))
end

#expand_excluded(uri, composer) ⇒ Array<URI>

Expands URIs with wildcards



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/puppet/pops/binder/scheme_handler/module_scheme.rb', line 88

def expand_excluded(uri, composer)
  result = []
  split_name, fqn = fqn_from_path(uri)

  case split_name[ 0 ]
  when '*'
    # create new URIs, one per module name
    composer.name_to_module.each_pair do | name, mod |
      result << URI.parse('module:/' + ([name] + split_name).join('::'))
    end

  when nil
    raise ArgumentError, "Bad bindings uri, the #{uri} has neither module name or wildcard '*' in its first path position"
  else
    # create a clean copy (get rid of optional, fragments etc. and any trailing stuff
    result << URI.parse('module:/' + split_name.join('::'))
  end
  result
end

#expand_included(uri, composer) ⇒ Array<URI>

Expands URIs with wildcards and checks optionality.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/puppet/pops/binder/scheme_handler/module_scheme.rb', line 36

def expand_included(uri, composer)
  result = []
  split_name, fqn = fqn_from_path(uri)

  # supports wild card in the module name
  case split_name[0]
  when '*'
    # create new URIs, one per module name that has a corresponding data_provider entry in metadata.json
    # or an .rb file relative to its '<root>/lib/puppet/bindings/'
    #
    composer.name_to_module.each_pair do | module_name, mod |
      expanded_name_parts = [module_name] + split_name[1..-1]
      expanded_name = expanded_name_parts.join('::')

      if is_metadata?(split_name)
        if mod. && mod.[METADATA_DATA_PROVIDER]
          result << URI.parse('module:/' + expanded_name)
        end
      elsif BindingsLoader.loadable?(mod.path, expanded_name)
        result << URI.parse('module:/' + expanded_name)
      end
    end
  when nil
    raise ArgumentError, "Bad bindings uri, the #{uri} has neither module name or wildcard '*' in its first path position"
  else
    joined_name = split_name.join('::')
    module_name = split_name[0]
    # skip optional uri if it does not exist
    if is_optional?(uri)
      mod = composer.name_to_module[module_name]
      unless mod.nil?
        if is_metadata?(split_name)
          if mod. && mod.[METADATA_DATA_PROVIDER]
            result << URI.parse('module:/' + joined_name)
          end
        elsif BindingsLoader.loadable?(mod.path, joined_name)
          result << URI.parse('module:/' + joined_name)
        end
      end
    else
      # assume it exists (do not give error if not, since it may be excluded later)
      result << URI.parse('module:/' + joined_name)
    end
  end
  result
end