Skip to content

Commit

Permalink
Return nil for failed lookups (empty hashes and empty arrays).
Browse files Browse the repository at this point in the history
  • Loading branch information
cestith committed Mar 17, 2014
1 parent 91811c2 commit 0b85efa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ running `hiera applications` would run the query against the configured database

The default_query key is special: it is in fact a default for anything in this hierarchy that is not specified with its own key. For example, running `hiera booksdb` would run default_query with the key variable in the query being interpolated as "booksdb".

Empty arrays and empty hashes returned from the database will be collapsed to nil as Puppet modules expect. Empty (zero-length) non-nil string values returned by the query suggest an actual empty column in the database and are returned as empty strings.

### Using

Expand Down Expand Up @@ -58,8 +59,7 @@ Hiera configuration is pretty simple

## Known issues

1. It always return an Array of hashes regardless of the number of items returned. (I did this on purpose because it is what I needed but I may be persuaded to do otherwise)
2. This README is poorly written.
1. This README is poorly written.


## Contributing
Expand Down
7 changes: 6 additions & 1 deletion lib/hiera/backend/postgres_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def lookup(key, scope, order_override, resolution_type)
end

end
return answer
unless answer.kind_of? String
if answer.empty?
answer = nil
end
end
return answer
end


Expand Down

0 comments on commit 0b85efa

Please sign in to comment.