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

(FACT-2317) Add Facter.define_fact method #2102

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/facter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ def debugonce(message)
nil
end

# Define a new fact or extend an existing fact.
#
# @param name [Symbol] The name of the fact to define
# @param options [Hash] A hash of options to set on the fact
#
# @return [Facter::Util::Fact] The fact that was defined
#
# @api public
def define_fact(name, options = {}, &block)
options[:fact_type] = :custom
LegacyFacter.define_fact(name, options, &block)
end

def on_message(&block)
Facter::Log.on_message(&block)
end
Expand Down
10 changes: 10 additions & 0 deletions spec/facter/facter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ def mock_collection(method, os_name = nil, error = nil)
end
end

describe '#define_fact' do
it 'sends call to LegacyFacter' do
allow(LegacyFacter).to receive(:define_fact)

Facter.define_fact('fact_name') {}

expect(LegacyFacter).to have_received(:define_fact).once.with('fact_name', { fact_type: :custom })
end
end

describe '#trace?' do
it 'returns trace variable' do
expect(Facter).not_to be_trace
Expand Down