Skip to content

Instantly share code, notes, and snippets.

@zaphod42
Last active January 1, 2016 06:39
Show Gist options
  • Select an option

  • Save zaphod42/8106852 to your computer and use it in GitHub Desktop.

Select an option

Save zaphod42/8106852 to your computer and use it in GitHub Desktop.
# 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
@adrienthebo

Copy link
Copy Markdown

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 interpret method and generates the final value. Multiple definitions can be defined, and are ordered by weight. This acts like a Facter::Util::Fact in that it holds a fully resolved value, and acts like a Facter::Util::Resolution in 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?

@zaphod42

Copy link
Copy Markdown
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