• Stars
    star
    272
  • Rank 151,235 (Top 3 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Elixir library for generating struct constructors that handle external data with ease.

ExConstructor

Build Status Coverage Status Hex.pm Version

ExConstructor is an Elixir library that makes it easy to instantiate structs from external data, such as that emitted by a JSON parser.

Add use ExConstructor after a defstruct statement to inject a constructor function into the module.

The generated constructor, called new by default, handles map-vs-keyword-list, string-vs-atom-keys, and camelCase-vs-under_score input data issues automatically, DRYing up your code and letting you move on to the interesting parts of your program.

Example

defmodule TestStruct do
  defstruct field_one: nil,
            field_two: nil,
            field_three: nil,
            field_four: nil
  use ExConstructor
end

TestStruct.new(%{"field_one" => "a", "fieldTwo" => "b", :field_three => "c", :FieldFour => "d"})
# => %TestStruct{field_one: "a", field_two: "b", field_three: "c", field_four: "d"}

Full ExConstructor documentation is available on Hexdocs.pm.

Contributors

Many thanks to those who've contributed to ExConstructor:

How to Contribute

My favorite contributions are PRs with code that matches project style, and that come with full test coverage and documentation. I have a hard time saying no to them.

Feature requests are also welcome, but the timeline may be much longer.

Bug reports are great -- please include as much information as possible (Erlang/Elixir/Mix version, dependencies and their versions, minimal test case, etc.) and I will be much quicker in resolving the issue.

Authorship and License

ExConstructor is copyright 2016-2021 Appcues, Inc.

ExConstructor is released under the MIT License.

More Repositories

1

mojito

An easy-to-use Elixir HTTP client, built on the low-level Mint library.
Elixir
348
star
2

gen_retry

Utilities for retrying Elixir functions, with configurable delay and backoff.
Elixir
197
star
3

snabbdom-virtualize

Library for turning strings and DOM nodes into virtual DOM nodes compatible with snabbdom.
JavaScript
36
star
4

highcharts-themes

Super slick themes for Highcharts
CoffeeScript
28
star
5

strip_js

An Elixir library for stripping executable JS from HTML and CSS.
Elixir
13
star
6

config_smuggler

Encodes Elixir configs to and from string-formatted key/value pairs.
Elixir
12
star
7

appcues-android-sdk

The Appcues Android SDK
Kotlin
10
star
8

ueberauth_okta

Okta strategy for Überauth
Elixir
9
star
9

appcues-react-native-module

The Appcues React Native Module
JavaScript
8
star
10

appcues-ios-sdk

The Appcues iOS SDK
Swift
7
star
11

stifle

Trap, observe, and release an Elixir function's side effects
Elixir
6
star
12

batch_please

Batch collector and processor for Elixir
Elixir
6
star
13

lockring

A fast mutex library for Elixir and other BEAM languages.
Elixir
6
star
14

appcues-flutter-plugin

The Appcues Flutter Plugin Package
Dart
4
star
15

segment-appcues-android

The Appcues Android SDK integration with Segment
Shell
3
star
16

useronboarding.org

CSS
3
star
17

ets_lock

An Elixir library for acquiring exclusive locks on ETS data.
Elixir
2
star
18

redis_cache

A wrapper for Redis which provides basic cache functionality in Elixir.
Elixir
2
star
19

segment-appcues-ios

The Appcues iOS SDK integration with Segment
Shell
2
star
20

jorb

Jorb is a simple jobs publisher/processor for Elixir
Elixir
1
star
21

email-templates

Collections of resources for Appcues email campaigns
HTML
1
star
22

microsites

CSS
1
star
23

appcues-capacitor-plugin

The Appcues Capacitor Plugin for Ionic Apps
TypeScript
1
star
24

react-starting-point

JavaScript
1
star
25

events

CSS
1
star
26

coffeecues

A rust HTTP server conforming to RFC 2324
Rust
1
star
27

brand

Public branding material for Appcues. Mostly because we love git :]
HTML
1
star
28

segment_spec

A simple Elixir data model for the events from Segment.com's spec.
Elixir
1
star
29

bbdd

Boop Boop Dedupe
Elixir
1
star