Skip to content

Commit

Permalink
added more documentation, bump to version 0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Dec 13, 2019
1 parent c3788b6 commit a94203b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.1.4

* Enhancements
* added support for duration nad period unit format
* added more tests
* extended the documentation
* added support for includes

## 0.1.3

* Enhancements
Expand Down
34 changes: 31 additions & 3 deletions lib/hocon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Hocon do
## Units format
The Parser returns a map, because in Elixir it is a common use case to use pattern matching on maps to
The parser returns a map, because in Elixir it is a common use case to use pattern matching on maps to
extract specific values and keys. Therefore the `Hocon.decode/2` function returns a map. To support
interpreting a value with some family of units, you can call some conversion functions like `as_bytes/1`.
Expand All @@ -24,6 +24,35 @@ defmodule Hocon do
iex> Hocon.as_bytes(limit)
524288
It is possible to access the unit formats by a keypath, as well:
## Example
iex> conf = ~s(a { b { c { limit : "512KB" } } })
iex> {:ok, map} = Hocon.decode(conf)
iex> Hocon.get_bytes(map, "a.b.c.limit")
524288
iex> Hocon.get_size(map, "a.b.c.limit")
512000
## Include
HOCON supports including of other configuration files. The default implmentation uses the file systems, which
seems to be the most used use case. For other user cases you can implement the `Hocon.Resolver` behaviour and
call the `decode/2` function with `resolver: MyResolver` as an option.
## Example
The file `include-1.conf` exists and has the following content:
{ x : 10, y : ${a.x} }
In the case we use the Hocon.FileResolver (which is the default as well):
iex> conf = ~s({ a : { include "./test/data/include-1" } })
iex> Hocon.decode(conf, resolver: Hocon.FileResolver)
{:ok, %{"a" => %{"x" => 10, "y" => 10}}}
To minize the dependencies of other packages, a seperate package will be provided to resolve url resource.
"""

alias Hocon.Parser
Expand Down Expand Up @@ -67,12 +96,11 @@ defmodule Hocon do
* `:convert_numerically_indexed` - if set to true then numerically-indexed objects are converted to arrays
* `:strict_conversion` - if set to `true` then numerically-indexed objects are only converted to arrays
if all keys are numbers
* `:resolver` - set to the module, which is responsible for loading the file/url resources. Default is `Hocon.FileResolver`
* `:resolver` - set to the module, which is responsible for loading the file/url resources. The default is `Hocon.FileResolver`
## Example
iex> conf = ~s(animal { favorite : "dog" }, key : \"\"\"${animal.favorite} is my favorite animal\"\"\")
"animal { favorite : \\"dog\\" }, key : \\"\\"\\"${animal.favorite} is my favorite animal\\"\\"\\""
iex> Hocon.decode(conf)
{:ok,
%{"animal" => %{"favorite" => "dog"}, "key" => "dog is my favorite animal"}}
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Hocon.MixProject do
use Mix.Project

@version "0.1.3"
@version "0.1.4"

def project do
[
Expand Down Expand Up @@ -47,7 +47,7 @@ defmodule Hocon.MixProject do
end

defp docs() do
[main: "readme",
[main: "Hocon",
name: "HOCON",
extras: ["README.md"],
source_ref: "v#{@version}",
Expand Down

0 comments on commit a94203b

Please sign in to comment.