Last active
January 1, 2016 06:39
-
-
Save zaphod42/8106852 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # create a resolution (instrument. It observes facts about the world) without any externally visible fact | |
| Facter.instrument(:network) do | |
| description "..." | |
| confine ... | |
| observe do | |
| ... | |
| end | |
| end | |
| # Create a specific composition, which is the final fact. Without the | |
| # definition a resolution doesn't show up. We "define" a fact as the | |
| # "interpretation" of the observed values from the available "instruments" | |
| Facter.define(:network) do | |
| interpret do |available_instruments| | |
| available_instruments.inject({}) do |combined, r| | |
| r.value.merge(combined) | |
| end | |
| end | |
| end | |
| #################################################### | |
| # create a resolution with a basic composition (mimics current facter behavior) | |
| Facter.add(:network) do | |
| description "..." | |
| confine ... | |
| observe do | |
| ... | |
| end | |
| end | |
| #the above is the equivalent of creating the instrument and a definition as | |
| Facter.define(:network) do | |
| interpret do |available_instruments| | |
| real_instrument = available_instruments.find { |r| !r.value.nil? } | |
| real_instrument.value | |
| end | |
| end | |
| #################################################### | |
| # How do you define new interpretation of the instruments? | |
| # Each definition can declare that it has a particular weight | |
| Facter.define(:network) do | |
| description "This is a better combination of the network stuff" | |
| weight 500 | |
| interpret do |available_instruments| | |
| available_instruments[Random.rand(10)].value | |
| end | |
| end |
Author
I think that matches what I was getting at.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This defines new language for Facter, and I've been working on matching this with the existing implementation. Right now I'm trying to determine the semantics of the different classes. This is what I have so far:
Definition/Composition
Takes input values with the
interpretmethod and generates the final value. Multiple definitions can be defined, and are ordered by weight. This acts like aFacter::Util::Factin that it holds a fully resolved value, and acts like aFacter::Util::Resolutionin that multiple values can be defined and are ordered by weight.Instruments
Provides a specific method of interacting with the system and returning generated information. Instruments are associated with a single definition. Instruments can be confined to specific platforms and may have some sort of weighting.
Do these descriptions seem right?