Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-5929) Add mapping between runtime classes and puppet types #4883

Conversation

thallgren
Copy link
Contributor

This PR adds the ability to create mappings between runtime types (here, only ruby since the runtime is ruby) and types in the Puppet Type system. Mappings are declared using an alias like expression where the left hand side is a Runtime type (either a single type or array with regex + replacement) and the right hand side is either a Puppet type or an array with regex + replacement.

A mapping is registered in string form in the new class ImplementationRegistry. A loader (the effective loader at the place where the mapping occurs) is also part of the mapping. This means that the singleton registry will be able to produce a Type from a Runtime (or vice versa) from any place in the code. This is necessary since no loader is present in the majority of cases. The TypeCalculator in particular, have no access to a loader instance and it must be able to produce types from a mapping when type inference is performed.

This commit adds the ability to declare a mapping between a runtime
type pattern and a puppet type pattern to the PL parser and validator.
A mapping can be declares as:
```
type Runtime(ruby, [<pattern>, <repl>]) = [<pattern>, <repl>]
```
where <pattern> are regexps and <repl> are strings that references
groups in the regexps using \<n> syntax.
@@ -103,7 +101,7 @@ def self.provide_from_name_path(name, name_path)
end

def self.find_class(name_path)
name_path.reduce(Object) do |ns, name|
name_path.inject(Object) do |ns, name|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always prefer reduce over inject (we use map/reduce as the paradigm instead of collect/inject).

@puppetcla
Copy link

CLA signed by all contributors.

Makes the ClassLoader use the predefined constant
`TypeFormatter::NAME_SEGMENT_SEPARATOR` and use `Array#shift` to pop
first element of array instead of creating a copy using a range.
@thallgren thallgren force-pushed the issue/pup-5929/type-alias-runtime-mapping branch from 7ec7fa2 to 96fdf07 Compare April 14, 2016 13:33
This commit adds the ImplementationRegistry that is the keeper of all
registered type mappings. The registry is string based so that types
and implementations can be mapped without being required to exists
at the time of mapping.
This commit changes the `TypeCalculator#infer` method so that it makes
an attempt to find a mapped Puppet type before it concludes that an
instance is a Runtime type.
@thallgren thallgren force-pushed the issue/pup-5929/type-alias-runtime-mapping branch from 96fdf07 to 09b921d Compare April 14, 2016 13:37
@hlindberg hlindberg merged commit a47f670 into puppetlabs:master Apr 14, 2016
@thallgren thallgren deleted the issue/pup-5929/type-alias-runtime-mapping branch April 25, 2016 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants