Skip to content

Commit

Permalink
Add docs for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nesaulov committed Feb 24, 2018
1 parent d5fbf57 commit 8024bb3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Expand Up @@ -38,6 +38,7 @@ to serialize nested objects and structures. [Introductory blogpost.](https://med
* [Include root](#include-root)
* [Root](#root)
* [Include namespaces](#include-namespaces)
* [Configuration](#configuration)
* [Bool and Any](#bool-and-any)
* [Type errors](#type-errors)
* [Undefined methods in schema](#undefined-methods-in-schema)
Expand Down Expand Up @@ -654,6 +655,31 @@ withdraws.surrealize(include_namespaces: true, namespaces_nesting_level: 2)
# => '{ "report_system": { "withdraws": { "withdraws_amount": 34 } } }'
```

### Configuration

There are two ways of setting default arguments for serialization,
by passing a block to `Surrealist.configure`:
```ruby
Surrealist.configure do |config|
config.camelize = true
config.namespaces_nesting_level = 2
end
```
And by passing a hash:

`Surrealist.configure(camelize: true, include_root: true)`

These arguments will be applied to all calls of `#build_schema` and `#surrealize`.
If these methods will be called with arguments, they will be merged with respect to explicitly passed ones:

```ruby
Surrealist.configure(camelize: true, include_root: true)

Something.new.surrealize(camelize: false)
# will result in Something.new.surrealize(camelize: false, include_root: true)
```


### Bool and Any
If you have a parameter that is of boolean type, or if you don't care about the type, you
can use `Bool` and `Any` respectively.
Expand Down

0 comments on commit 8024bb3

Please sign in to comment.