Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spacepilots/mason
Mason uses superpowers to coerce maps into structs. This is helpful e.g. when you interface a REST API and want to create a struct from the response.
https://github.com/spacepilots/mason
Last synced: about 1 month ago
JSON representation
Mason uses superpowers to coerce maps into structs. This is helpful e.g. when you interface a REST API and want to create a struct from the response.
- Host: GitHub
- URL: https://github.com/spacepilots/mason
- Owner: spacepilots
- License: mit
- Created: 2018-06-21T08:36:08.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2018-06-21T11:48:16.000Z (over 6 years ago)
- Last Synced: 2024-10-04T10:19:35.066Z (2 months ago)
- Language: Elixir
- Homepage:
- Size: 4.88 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Coerce maps into structs. This is helpful e.g. when you interface a REST API and want to create a struct from the response. (Algorithms and Data structures)
- fucking-awesome-elixir - mason - Coerce maps into structs. This is helpful e.g. when you interface a REST API and want to create a struct from the response. (Algorithms and Data structures)
- awesome-elixir - mason - Coerce maps into structs. This is helpful e.g. when you interface a REST API and want to create a struct from the response. (Algorithms and Data structures)
README
# Mason ![Build Status](https://travis-ci.org/spacepilots/mason.svg?branch=develop)
Mason uses superpowers to coerce maps into structs. This is helpful e.g.
when you interface a REST API and want to create a struct from the response.```elixir
defmodule User do
defstruct [ :user_id, :created_at ]def masonstruct do
%{
createdAt: &({ :created_at, elem(DateTime.from_unix(&1), 1) }),
userId: &({ :user_id, &1 })
}
end
endresponse = %{ "userId" => 123, createdAt: 1456749030 }
Mason.struct User, response # %User{created_at: #DateTime<2016-02-29 12:30:30Z>, user_id: 123}
```## Features
* coerce to Elixir's built-in types from strings
* dynamically coerce values (e.g. timestamps to `DateTime`s)
* map keys (e.g. `createdAt` to `created_at`)
* convert string keys to atoms (e.g. `..., "age" => 29, ...` to `..., age: 29, ...`)
* convert lists## Installation
The package can be installed by adding `mason` to your list of
dependencies in `mix.exs`:```elixir
def deps do
[
{:mason, "~> 0.1.0"}
]
end
```The docs can be found at [https://hexdocs.pm/mason](https://hexdocs.pm/mason).
## Contributing
* We use [gitflow](https://github.com/nvie/gitflow) (with the production branch
being `master` and the development branch being `develop`)
* and [semantic commit messages](https://seesparkbox.com/foundry/semantic_commit_messages).
* We use [semantic versioning](https://semver.org/).
* We use pull requests and run our test suite on [Travis CI](https://travis-ci.org/spacepilots/mason).