Skip to content

Commit

Permalink
Merge pull request #3 from cdaringe/refactor/casing
Browse files Browse the repository at this point in the history
refactor/casing
  • Loading branch information
cdaringe committed Feb 2, 2024
2 parents 2c5fe75 + 174f029 commit 0b44696
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ gleam add gserde

## usage

1. Create custom type with a singular variant constructor:
2. Run `gleam run -m gserde`
3. Observe `src/foo_json.gleam`, which has the goodies you need for json (de)serialization.
1. Create custom type with a singular variant constructor. See the example `src/foo.gleam` below.
2. Run `gleam run -m gserde`.
3. Observe the generated file `src/foo_json.gleam`.
4. Use it!

```gleam
// src/foo.gleam
import gleam/option.{type Option}
pub type FooJSON {
pub type FooJson {
Foo(
a_bool: Bool,
b_int: Int,
Expand Down
2 changes: 1 addition & 1 deletion src/gserde.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn process_single(src_filename: String) {

let custom_types =
list.map(parsed.custom_types, fn(def) { def.definition })
|> list.filter(fn(x) { string.ends_with(x.name, "JSON") })
|> list.filter(fn(x) { string.ends_with(x.name, "Json") })
let requests =
custom_types
|> list.flat_map(fn(custom_type) {
Expand Down
2 changes: 1 addition & 1 deletion test/gserde_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn main() {
}

const foo_module = "import gleam/option.{type Option}
pub type FooJSON {
pub type FooJson {
Foo(
a_bool: Bool,
b_int: Int,
Expand Down

0 comments on commit 0b44696

Please sign in to comment.