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

Make symbolize keys optional #362

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions lib/facterdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,17 @@ def self.valid_filters?(filters)

# @return [Array[Hash[Symbol, Any]]] array of hashes of facts
# @param filter [Object] The filter to convert to jgrep string
def self.get_facts(filter = nil, cache = true)
# @param symbolize_keys [Boolean]
# Whether to symbolize the keys. Note this is only on the top level and not
# on nested values.
def self.get_facts(filter = nil, cache = true, symbolize_keys: true)
if cache && filter && filter == Thread.current[:facterdb_last_filter_seen]
return Thread.current[:facterdb_last_facts_seen]
end

filter_str = generate_filter_str(filter)
result = JGrep.jgrep(database, filter_str).map { |hash| hash.map { |k, v| [k.to_sym, v] }.to_h }
result = JGrep.jgrep(database, filter_str)
result = result.map { |hash| hash.transform_keys(&:to_sym) } if symbolize_keys
if cache
Thread.current[:facterdb_last_filter_seen] = filter
Thread.current[:facterdb_last_facts_seen] = result
Expand Down
Loading