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
@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