profile
viewpoint
Jean-Philippe Cugnet ejpcmac Port-aux-Français, Kerguelen Islands https://ejpcmac.net Overwintering in Kerguelen Islands from November 2019 to December 2020. Please reach me via email if necessary. I may receive notifications from GitHub, too.

ejpcmac/expected 30

An Elixir application for login and session management.

ejpcmac/plug_session_mnesia 19

An Elixir application for storing and managing Plug sessions with Mnesia.

ejpcmac/config_files 11

Personal configuration framework.

ejpcmac/marcus 3

A library for writing interactive CLIs in Elixir.

ejpcmac/confkit 2

A configuration framework using Nix.

ejpcmac/diceware 2

A Rust implementation of Diceware.

ejpcmac/export_private 1

An Elixir module for exporting private functions in tests.

ejpcmac/arc_ecto 0

An integration with Arc and Ecto.

ejpcmac/asdf-elixir 0

Elixir plugin for asdf version manager

ejpcmac/cargo-cacher 0

A caching server for crates + cargo

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha 67e8bd91d3f9fbd185fa7b55955a1863f0a6d63b

[Zsh/Xen] Add aliases for Xen

view details

push time in 2 hours

startedillumos/illumos-gate

started time in a day

startedjoyent/triton

started time in a day

startedsmackers/smack

started time in 3 days

startednix-community/impermanence

started time in 6 days

startedAleXoundOS/nix-mirror

started time in 7 days

startedimsnif/diskonaut

started time in 7 days

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha 2088af188f1c9afe938755f2d06cf53718a663cf

[Example] Simplify and update the example

view details

push time in 7 days

startedzacps/blocked

started time in 11 days

startedQqwy/elixir-blocked

started time in 11 days

release ejpcmac/confkit

v0.0.8

released time in 22 days

created tagejpcmac/confkit

tagv0.0.8

A configuration framework using Nix.

created time in 22 days

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha 5d2103ca052fc76ea2ae5a1cfc65a89f1254aad3

Merge tag 'v0.0.7' into develop

view details

Jean-Philippe Cugnet

commit sha 4a838d1d2fab11f088c77b3eb83ab1bc205360ba

[Zsh/Elixir] Add mck for mix check

view details

Jean-Philippe Cugnet

commit sha ba2b6d6ab0b8fc204d9fc675fa2a70d1bd45bd91

[Nix/Environment & Zsh/Nix] Do not create /run/user/0 on rebuild

view details

Jean-Philippe Cugnet

commit sha c6d72a0d5e02bf1e3b2dac470ae4f5d77c50e1a4

[CHANGELOG] Switch to the “Keep a Changelog” format

view details

Jean-Philippe Cugnet

commit sha ad6142d8dfed6487e895cca622e0c09426dd69ee

[ranger/bepo] Add `\.` for `fusermount -u %s`

view details

Jean-Philippe Cugnet

commit sha c01cd718c0abbdddd5611622a3106c1a4845d6ef

[ranger] Add a QWERTY/AZERTY configuration

view details

Jean-Philippe Cugnet

commit sha 18b3203563d8c3d45b79ac3b24a842ae1459e067

[ranger] Make the BÉPO configuration on par with the QWERTY one

view details

Jean-Philippe Cugnet

commit sha a2b145aa6968c1588dd216fef1b13ca68c28bc50

[Tmux] Remove the Tmux 2.3 configuration

view details

Jean-Philippe Cugnet

commit sha 377e4384b5938fe9052c2be80d46fceda833eddd

[Tmux] Add a configuration for BÉPO keyboards

view details

Jean-Philippe Cugnet

commit sha bfb17876f8e7d91931da67eb80fd9476ee2a4b4b

[Nix/Tmux] Add the programs.tmux.useBepoKeybindings option

view details

Jean-Philippe Cugnet

commit sha f1deaa4fa8847377af1a2fc4f8206db6261bd111

Bump the version to 0.0.8

view details

Jean-Philippe Cugnet

commit sha 0bca1d04167c31b502a37a931ffd7c59dd4b9dc1

Merge branch 'release/0.0.8'

view details

push time in 22 days

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha f1deaa4fa8847377af1a2fc4f8206db6261bd111

Bump the version to 0.0.8

view details

Jean-Philippe Cugnet

commit sha 0bca1d04167c31b502a37a931ffd7c59dd4b9dc1

Merge branch 'release/0.0.8'

view details

Jean-Philippe Cugnet

commit sha 21fba08303780a40588322541127a180d6df9210

Merge tag 'v0.0.8' into develop

view details

push time in 22 days

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha a2b145aa6968c1588dd216fef1b13ca68c28bc50

[Tmux] Remove the Tmux 2.3 configuration

view details

Jean-Philippe Cugnet

commit sha 377e4384b5938fe9052c2be80d46fceda833eddd

[Tmux] Add a configuration for BÉPO keyboards

view details

Jean-Philippe Cugnet

commit sha bfb17876f8e7d91931da67eb80fd9476ee2a4b4b

[Nix/Tmux] Add the programs.tmux.useBepoKeybindings option

view details

push time in 22 days

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha c01cd718c0abbdddd5611622a3106c1a4845d6ef

[ranger] Add a QWERTY/AZERTY configuration

view details

Jean-Philippe Cugnet

commit sha 18b3203563d8c3d45b79ac3b24a842ae1459e067

[ranger] Make the BÉPO configuration on par with the QWERTY one

view details

push time in 22 days

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha ad6142d8dfed6487e895cca622e0c09426dd69ee

[ranger/bepo] Add `\.` for `fusermount -u %s`

view details

push time in 22 days

issue openeduberbrodt/ex_constructor

Make ex_constructor a TypedStruct plugin

Since upstream TypedStruct 0.2.0 now supports plugins, Contructor could be a plugin. This way, it would be composable with other TypedStruct plugins.

The API would look like:

defmodule ConstructorExampleUser do
  use TypedStruct

  # Use the “standard” typedstruct macro.
  typedstruct do
    plugin Constructor # Register Constructor as a plugin. Code can be injected here.
    plugin TypedStructLens # Let’s say we also want to generate lenses.

    field :id, integer(), constructor: &is_integer/1, enforce: true
    field :role,  :user | :admin, constructor: &is_valid_role/1, enforce: true
    field :first_name, String.t(), default: "", constructor: &is_string/1
    field :last_name, String.t(), default: "", constructor: &is_string/1
  end

  def is_valid_role(value) do
    case value do
      :admin -> {:ok, value}
      :user -> {:ok, value}
      _ -> {:error, "invalid role!"}
    end
  end
end

created time in a month

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha c6d72a0d5e02bf1e3b2dac470ae4f5d77c50e1a4

[CHANGELOG] Switch to the “Keep a Changelog” format

view details

push time in a month

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha e6745e3010710b2aa115e2904b9222f134aec141

[CHANGELOG] Switch to the “Keep a Changelog” format

view details

push time in a month

issue closedNixOS/nixpkgs

emacsclient does not work in Nix shells due to changed TMPDIR

Issue description

On NixOS, TMPDIR is not set by default, but it is set to /run/user/$UID in Nix shells.

If I set services.emacs.enable = true, an Emacs daemon is started automatically by systemd, using the system environment. This, as TMPDIR is not defined, the socket is created under /tmp.

If I use emacsclient outside of a Nix shell, all works properly. Now, if I use emacsclient inside a Nix shell, it looks for the socket under /run/user/$UID as TMPDIR is set: it does not work.

Steps to reproduce

  1. Start an Emacs daemon outside of a Nix shell
  2. Start a Nix shell
  3. Run emacsclient -c: it does not work

Technical details

  • system: "x86_64-linux"
  • host os: Linux 4.19.16, NixOS, 19.03pre166987.bc41317e243 (Koi)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.2
  • channels(root): "home-manager, jpc-nix, nixos-19.03pre166987.bc41317e243"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Possible workarounds

  1. Setting an emacsclient alias prefixed by TPMDIR=/tmp. This would work as expected, but it would be platform-specific: on macOS for instance, the TMPDIR is correctly set both inside and outside Nix shells.

  2. Setting environment.variables.TPMDIR = "/run/user/$UID";. I went for this one, but I a now facing another issue: when running nixos-rebuild switch after a reboot, I get a /run/user/0 not found error, and I need to manually create this directory.

Is there any reason TMPDIR is not set outside Nix shells?

closed time in a month

ejpcmac

issue commentNixOS/nixpkgs

emacsclient does not work in Nix shells due to changed TMPDIR

Effectively, after removing my custom TMPDIR I’m not hit by this issue anymore, since my use case has evolved. Let’s say it’s a very specific issue that don’t affect many people, so we can close it and focus on more important things :)

ejpcmac

comment created time in a month

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha ba2b6d6ab0b8fc204d9fc675fa2a70d1bd45bd91

[Nix/Environment & Zsh/Nix] Do not create /run/user/0 on rebuild

view details

push time in a month

issue commentNixOS/nixpkgs

emacsclient does not work in Nix shells due to changed TMPDIR

@aij Yes, I think the current behaviour is confusing. Nonetheless, I’m now using a shortcut in ranger to open Emacs in the current directory, and not emacsclient that often, so maybe I wouldn’t be hit by this issue so much in fact. Let’s try to unset my TMPDIR and see if I still have issues with my current workflow.

ejpcmac

comment created time in a month

push eventejpcmac/config_files

Jean-Philippe Cugnet

commit sha 82e10ccc8540c52f1cc949ca17c4e98e68882755

Update the README.md

view details

push time in a month

push eventejpcmac/config_files

Jean-Philippe Cugnet

commit sha 35e2dffd41493e489a68383a0d7aa51191b79dfd

Update from the private repository

view details

push time in a month

startedmarcelotto/behaviour_reflection

started time in a month

issue commentNixOS/nixpkgs

emacsclient does not work in Nix shells due to changed TMPDIR

I still use the workaround from my first post, and it still feels hacky to define it this way.

ejpcmac

comment created time in a month

issue commentNixOS/nixpkgs

`boot.initrd.network.ssh.hostRSAKey` breaks activation if removed

What’s the state of this issue today? I have not modified this setting recently on any of my systems, but hitting this issue while re-installing a system could lead to confusion.

Baughn

comment created time in a month

issue commentNixOS/nixpkgs

Firefox-bin does not detect language

This is still an issue today.

artemist

comment created time in a month

issue closedejpcmac/typed_struct

Feature request : integeration with a lens library

Hi,

Did you consider providing some integration with one or more lens libraries ?

https://github.com/tpoulsen/focus → they already have a "deflens" macro, that defines struct and lenses at the same time https://github.com/obrok/lens → seems more feature complete

Thanx for your library !

closed time in a month

fcabouat

issue commentejpcmac/typed_struct

Feature request : integeration with a lens library

You can now use TypedStruct 0.2.0 with typed_struct_lens.

fcabouat

comment created time in a month

release ejpcmac/typed_struct_lens

v0.1.0

released time in a month

created tagejpcmac/typed_struct_lens

tagv0.1.0

A TypedStruct plugin for defining a lens on each field without writing boilerplate code.

created time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha ce1499e8533c33ea1ec90dca8085e6c50c03ea59

Implement the plugin

view details

Jean-Philippe Cugnet

commit sha 4f9e23932e71d6c083b15f06c9109eab6eb50f20

Add prefix and postfix options for the lens name

view details

Jean-Philippe Cugnet

commit sha fc91fbbda5789a1f574675086aacd035f5f17108

Use the Keep a Changelog format

view details

Jean-Philippe Cugnet

commit sha d13f188b32eb4fbdd611dca9ac9fc8a3cee364b1

Update the development environment

view details

Jean-Philippe Cugnet

commit sha 5aeb7d0174764ad6a6cb2b23482e51346230ff8c

[CI] Update the configuration and use ex_check

view details

Jean-Philippe Cugnet

commit sha 58d3d189258510dbcc112cdb75390cee60fceb79

Update the Credo configuration

view details

Jean-Philippe Cugnet

commit sha 23d625bc5daaa8291a10eea699aa5e84e510184d

Update the dependencies (from my local offline hex.pm mirror)

view details

Jean-Philippe Cugnet

commit sha 77d90ddb881e16ec743fc6da94a71ecc5f1a1b17

Write the documentation

view details

Jean-Philippe Cugnet

commit sha c4ad71a78f78b5101b02b7dc0f0c5bfb4289ee1d

Bump the version to 0.1.0

view details

Jean-Philippe Cugnet

commit sha 706d4c7a8a59fbc3ea84c3dc15d9f2295e6be6a6

Update the Copyright

view details

Jean-Philippe Cugnet

commit sha ae93c724997615a2ec0244eeb64b5519d4ff39d5

Fix typos in the documentation

view details

Jean-Philippe Cugnet

commit sha 89ea968bd02e2cab228b0df5edf96e93d97f0bc2

Update the dependencies (after updating my mirror)

view details

Jean-Philippe Cugnet

commit sha 4b93097c0c1e981728776d1484e876ec351acda4

Use typed_struct 0.2.0 from hex.pm

view details

Jean-Philippe Cugnet

commit sha 0d26601e4a3ef4bfa6e905a4e6dbb68eed75c230

Update the release date

view details

Jean-Philippe Cugnet

commit sha d952918a28391b5aad5229d58a2aee4b59d61c87

Merge branch 'release/0.1.0'

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha c4ad71a78f78b5101b02b7dc0f0c5bfb4289ee1d

Bump the version to 0.1.0

view details

Jean-Philippe Cugnet

commit sha 706d4c7a8a59fbc3ea84c3dc15d9f2295e6be6a6

Update the Copyright

view details

Jean-Philippe Cugnet

commit sha ae93c724997615a2ec0244eeb64b5519d4ff39d5

Fix typos in the documentation

view details

Jean-Philippe Cugnet

commit sha 89ea968bd02e2cab228b0df5edf96e93d97f0bc2

Update the dependencies (after updating my mirror)

view details

Jean-Philippe Cugnet

commit sha 4b93097c0c1e981728776d1484e876ec351acda4

Use typed_struct 0.2.0 from hex.pm

view details

Jean-Philippe Cugnet

commit sha 0d26601e4a3ef4bfa6e905a4e6dbb68eed75c230

Update the release date

view details

Jean-Philippe Cugnet

commit sha d952918a28391b5aad5229d58a2aee4b59d61c87

Merge branch 'release/0.1.0'

view details

Jean-Philippe Cugnet

commit sha f90d416d147e002421cfa87d78d93bfd8595aa3f

Merge tag 'v0.1.0' into develop

view details

push time in a month

delete branch ejpcmac/typed_struct_lens

delete branch : release/0.1.0

delete time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 4b93097c0c1e981728776d1484e876ec351acda4

Use typed_struct 0.2.0 from hex.pm

view details

Jean-Philippe Cugnet

commit sha 0d26601e4a3ef4bfa6e905a4e6dbb68eed75c230

Update the release date

view details

push time in a month

release ejpcmac/typed_struct_legacy_reflection

v1.0.0

released time in a month

created tagejpcmac/typed_struct_legacy_reflection

tagv1.0.0

A TypedStruct plugin re-enabling the legacy reflection functions from TypedStruct 0.1.x.

created time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha 1af50089f8a00afb9a57ce44bb55425225fa5642

Implement the reflection API from TypedStruct 0.1.x

view details

Jean-Philippe Cugnet

commit sha f2a3a86512d95b0a2186df199fe272166184c883

[CI] Fix the configuration with Dialyxir 1.0.0-rc.7

view details

Jean-Philippe Cugnet

commit sha 0623f7966c3ab2719cfd6de68fbc466fd140916d

Use the Keep a Changelog format

view details

Jean-Philippe Cugnet

commit sha b13b9cbee48dd2de6459f94ed3f588d812204970

Update the development environment

view details

Jean-Philippe Cugnet

commit sha ded24ef950c9d9760f4bfb951fdbebc86feb0a3f

[CI] Update the configuration and use ex_check

view details

Jean-Philippe Cugnet

commit sha 0332994174d3586dd1ce44a4013904844329f906

Update the Credo configuration

view details

Jean-Philippe Cugnet

commit sha 789cb6115f1a8d31752b7f2dbbaf79cd5ff83675

Update typed_struct to branch release/0.2.0

view details

Jean-Philippe Cugnet

commit sha ead6520f54ec1a5c59e66fcc9bd3e1fef123942e

Update the documentation

view details

Jean-Philippe Cugnet

commit sha ae11aacd6d66a8c238d76dbd993868e034f74af3

Bump the version to 1.0.0

view details

Jean-Philippe Cugnet

commit sha 2e35c6f4e9c143fa559681c9e131c4fb3e075878

Tiny fixes in the documentation and Copyright

view details

Jean-Philippe Cugnet

commit sha 1f6e1c1529ac038b10b02f488b7ea6176c9c704e

Update the dependencies (after updating my mirror)

view details

Jean-Philippe Cugnet

commit sha 5bac8e607d8c6752679118f01eebea757e0c44a1

Use typed_struct 0.2.0 from hex.pm

view details

Jean-Philippe Cugnet

commit sha a10b72cbe52e1a1a64a8627c2a25dfc4139acf12

Update the release date

view details

Jean-Philippe Cugnet

commit sha 15e1167186af6a824b4213f93b5569d96b0d21ac

Merge branch 'release/1.0.0'

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha ae11aacd6d66a8c238d76dbd993868e034f74af3

Bump the version to 1.0.0

view details

Jean-Philippe Cugnet

commit sha 2e35c6f4e9c143fa559681c9e131c4fb3e075878

Tiny fixes in the documentation and Copyright

view details

Jean-Philippe Cugnet

commit sha 1f6e1c1529ac038b10b02f488b7ea6176c9c704e

Update the dependencies (after updating my mirror)

view details

Jean-Philippe Cugnet

commit sha 5bac8e607d8c6752679118f01eebea757e0c44a1

Use typed_struct 0.2.0 from hex.pm

view details

Jean-Philippe Cugnet

commit sha a10b72cbe52e1a1a64a8627c2a25dfc4139acf12

Update the release date

view details

Jean-Philippe Cugnet

commit sha 15e1167186af6a824b4213f93b5569d96b0d21ac

Merge branch 'release/1.0.0'

view details

Jean-Philippe Cugnet

commit sha b17d951375e63ddfa7d4ec158c654b6a0b639694

Merge tag 'v1.0.0' into develop

view details

push time in a month

delete branch ejpcmac/typed_struct_legacy_reflection

delete branch : release/1.0.0

delete time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha 5bac8e607d8c6752679118f01eebea757e0c44a1

Use typed_struct 0.2.0 from hex.pm

view details

Jean-Philippe Cugnet

commit sha a10b72cbe52e1a1a64a8627c2a25dfc4139acf12

Update the release date

view details

push time in a month

release ejpcmac/typed_struct

v0.2.0

released time in a month

created tagejpcmac/typed_struct

tagv0.2.0

An Elixir library for defining structs with a type without writing boilerplate code.

created time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 44b25743abd4e3a2e1734d9cae889b08695bc867

Merge tag 'v0.1.4' into develop

view details

Chris Brodt

commit sha 56d35ea0fe7c09c0e912ddb6d1044ba3ecbfe9f3

Implemented a plugin system.

view details

Jean-Philippe Cugnet

commit sha c72eaf7fa2359b7e022c1395faa930ac48627120

Bump the version to 0.2.0-dev

view details

Jean-Philippe Cugnet

commit sha 3dc508ebc32b4a5bde68fe6ac8a692131ff9a73c

Update the copyrights

view details

Jean-Philippe Cugnet

commit sha 91b6b794a6ff93f92508712d108a8af04473918c

[CI] Update the configuration

view details

Jean-Philippe Cugnet

commit sha 220ccd6882f9fc6bf2c017dc394dfa3ae03ad616

Update the contributing guidelines

view details

Jean-Philippe Cugnet

commit sha 86dfc156146dd8b2aee553d2f34af4654b171d3e

Update the dependencies

view details

Jean-Philippe Cugnet

commit sha 67a6c5e3add7a36f15d47e29047e491515c81ccb

[CI] Exclude Elixir 1.8 on OTP 19.3

view details

Jean-Philippe Cugnet

commit sha 02a348c5e06fb4c7a22d235f13e451d509981a67

Merge pull request #12 from uberbrodt/plugin_system

view details

Jean-Philippe Cugnet

commit sha 9b804d0b6c72d399f924edfd9805f2a76993ae12

[Plugin API] Introduce a pre-final version reworked for flexibility This commit does not include tests nor documentation. It is provided to help integration in dependent libraries.

view details

Jean-Philippe Cugnet

commit sha 3ea328ba8b6f169f8dc1d7a72ff80c04fc9246c9

Create a scope in the typedstruct block to avoid leaks

view details

Jean-Philippe Cugnet

commit sha e2345370472aa5cf1f2af31616fad08956e23613

[Plugin API] Fix the init/1 callback not being optional to define

view details

Jean-Philippe Cugnet

commit sha a5dda3aff603709a4293b6ce059ee5100a2103d7

Enhance a bit the documentation

view details

Jean-Philippe Cugnet

commit sha 0051d13ff87fe98e74ddeb59183ac7e6f98d5b45

[Plugin API] Write the documentation

view details

Jean-Philippe Cugnet

commit sha cf89160374fb17d94bc2a5d79c5d6ce8a05a2f51

Write a test to ensure TypedStruct macros do not leak outside the block

view details

Jean-Philippe Cugnet

commit sha df33c143db9addd055b255543046c7c2fa7572a1

[Plugin API] Write some tests (closes #9)

view details

Jean-Philippe Cugnet

commit sha 1207e15291cad2dc21dd59945c88120272df3f5a

Make the section-separating comments more visible everywhere

view details

Jean-Philippe Cugnet

commit sha 4b4c8b0edb1765a7fcbe9eaf379c82cf1bf7feda

Do not enforce fields with a default value set to nil (fixes #14)

view details

Jean-Philippe Cugnet

commit sha 320a16b986d457b6727d67efb7e4ce4fcc901f5d

Prefix all internal module attributes and clean them after use (fixes #15)

view details

Jean-Philippe Cugnet

commit sha 7bd98fc2e9bbe4f73ccf5daa066c0edfe5eaafa5

Remove reflection support (closes #16) This is not needed anymore since the plugin API is there and more complete. For users relying on it, please use the typed_struct_legacy_reflection plugin.

view details

push time in a month

issue closedejpcmac/typed_struct

Remove built-in reflection support

From the very first version, TypedStruct has proposed some basic reflection support to let users build things using keys, types and default values from the defined struct. These values have been accessible through three functions defined in the modules using TypedStruct :

  • __keys__/0
  • __defaults__/0
  • __types__/0

The primary usage for me was to use TypedStruct in this module and still be able to partially generate this other module from its keys, default values an types. Finally I have not maintained Expected since then, thus never really used this feature from TypedStruct.

Now that TypedStruct includes a plugin system, generating a record from a struct with the associated translation helpers could be implemented as a plugin, which would be more interesting.

Provided that, I think generating these reflection functions directly in TypedStruct is not necessary anymore. If anyone uses them currently, I will provide a plugin that define them. For my own memory, the module to implement is:

defmodule TypedStructLegacyReflection do
  use TypedStruct.Plugin

  @impl true
  @spec after_definition(keyword()) :: Macro.t()
  def after_definition(_opts) do
    quote do
      def __keys__, do: @ts_fields |> Keyword.keys() |> Enum.reverse()
      def __defaults__, do: Enum.reverse(@ts_fields)
      def __types__, do: Enum.reverse(@ts_types)
    end
  end
end

and it would be use like this:

defmodule StructWithReflection do
  use TypedStruct

  typedstruct do
    plugin TypedStructLegacyReflection

    field :a_field, term()
    field :another_field, String.t()
  end
end

The plugin will be available concurrently to the release of TypedStruct 0.2.0, and a breaking change notice will appear in the changelog.

closed time in a month

ejpcmac

issue closedejpcmac/typed_struct

A field with a default value set to nil should not be enforced

When the struct has enforce: true, one can override this by setting a default value on a field. Something like this:

typedstruct enforce: true do
  field :non_enforced_field, integer, default: 42
end

But it is not possible to default to nil (it will not un-enforce the field:

typedstruct enforce: true do
  # This will not work. The field is still enforced
  field :non_enforced_field, integer | nil, default: nil
end

I know that adding enforce: false on the field will do the same thing, since nil is the default value for non-enforces fields, but for the explicitness and readability, it would be nice the set the default value to nil.

If you agree, @ejpcmac, I will be happy to give it a shot.

closed time in a month

lasseebert

issue closedejpcmac/typed_struct

Non-clashing module attributes

I just got hit by the auto generated module attributes (@fields, @types and @keys_to_enforce).

I was changing an existing defstruct to use TypedStruct, but I already had a module attribute called @types. It took me a while to figure out what went wrong :)

ExUnit and Ecto both solves this by prepending the library name to the module attributes.

Perhaps typed_struct could do the same?

I'd be happy to do a PR.

closed time in a month

lasseebert

issue closedejpcmac/typed_struct

Add a plugin system

Steps

  • [x] Start a toy project using TypedStruct and a plugin-to-be
  • [x] Find a plugin idea
  • [x] Start the plugin project
  • [x] Define the plugin API and try concepts (try #12)
  • [x] Merge #12
  • [x] Adapt to the final v0.2.0 API while trying the implementation
  • [x] Write documentation
  • [x] Write tests

Rationale

Structs are used to represent many things in Elixir. Other libraries sometimes provide their own macros to define special functions alongside the struct. While integrating them with TypedStruct could sometimes be handy, there are two main issues:

  1. there is potentially a large number of libraries to integrate and maintain compatibility with,
  2. it would add code to TypedStruct that would be use by only a restricted number of projects.

There are already features request for Ecto (#7) and lens libraries (#8). More could come, so I think a plugin system would be a better solution. While I do not see currently how it would fit for the Ecto case, simpler cases like defining special functions from the struct fields could be handled by a function:

defmodule MyStruct do
  use TypedStruct

  # This would contain the define_lenses/? function.
  # Its parameters and return type are yet to define.
  import LensPlugin

  typedstruct do
    plugin :define_lenses

    field :name, String.t()
    field :age, integer(), some: :option
  end
end

Plugin functions would be called after the fields have been processed, with any option like some: :option made available to it. The complete API is to define, but here is a first idea. It could be interesting to provide some helpers for users to define their own top-level macros to replace typedstruct or extending it. Integration with Ecto could be explored in such a way.

API definition

In its PR #12, @uberbrodt defines the plugin API as a behaviour. This seems to be a good start.

Plugin definition

A TypedStruct plugin is a module that implements the TypedStruct.Plugin behaviour. This behaviour is made of several callbacks, all optional to let some flexibility to the user:

  • @macrocallback init(opts): lets the user inject some code in the module before the fields are processed. This can be used to register attributes or adding new macros in the scope.
  • @callback field(name, type, opts): called on each field, after it has been processed by TypedStruct.
  • @callback after_fields(opts): called after the fields, but before the struct and type definition.

Plugin usage

defmodule MyStruct do
  use TypedStruct

  typedstruct do
    plugin FirstPlugin
    plugin WithOptions, some: :option, another: "option"

    field :name, String.t()
    field :age, integer(), some: :option
  end
end

Options passed to the plugins are passed to the callbacks. The field/4 callbacks gets both the field-specific options and the plugin general option in its opts keyword.

closed time in a month

ejpcmac

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha d547648a59d3055a76dd006e6dcdfbd47d3981f5

Bump the version to 0.2.0

view details

Jean-Philippe Cugnet

commit sha 72f407abc9e1478dbfb280d957ed949cc15dbbc2

Update the changelog

view details

Jean-Philippe Cugnet

commit sha 9acc3a4c1c5864d68975a22a5657bbcad0e8ac40

Update the Copyright

view details

Jean-Philippe Cugnet

commit sha 7ff4508b6d8a83a35c2004d44507631e9b06f7ff

Add links to the documentation in the README.md

view details

Jean-Philippe Cugnet

commit sha cb58dd2dc76a3136fee01acd9a8718d97cbb2807

Update the dependencies (after updating my mirror)

view details

Jean-Philippe Cugnet

commit sha 8a358cb399284cdd9133072a80275ae06009ea3a

Update the release date

view details

Jean-Philippe Cugnet

commit sha cd3765628cd6da2af414fae65d3e2a1e75723f06

Merge branch 'release/0.2.0'

view details

Jean-Philippe Cugnet

commit sha 20458b1f28bded31a5bcc05fc2b439c42d406180

Merge tag 'v0.2.0' into develop

view details

push time in a month

delete branch ejpcmac/typed_struct

delete branch : release/0.2.0

delete time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 8a358cb399284cdd9133072a80275ae06009ea3a

Update the release date

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha 1f6e1c1529ac038b10b02f488b7ea6176c9c704e

Update the dependencies (after updating my mirror)

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 89ea968bd02e2cab228b0df5edf96e93d97f0bc2

Update the dependencies (after updating my mirror)

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha cb58dd2dc76a3136fee01acd9a8718d97cbb2807

Update the dependencies (after updating my mirror)

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 7ff4508b6d8a83a35c2004d44507631e9b06f7ff

Add links to the documentation in the README.md

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha 2e35c6f4e9c143fa559681c9e131c4fb3e075878

Tiny fixes in the documentation and Copyright

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha ae93c724997615a2ec0244eeb64b5519d4ff39d5

Fix typos in the documentation

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 706d4c7a8a59fbc3ea84c3dc15d9f2295e6be6a6

Update the Copyright

view details

push time in a month

create barnchejpcmac/typed_struct_lens

branch : release/0.1.0

created branch time in a month

push eventejpcmac/typed_struct_lens

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha ce1499e8533c33ea1ec90dca8085e6c50c03ea59

Implement the plugin

view details

Jean-Philippe Cugnet

commit sha 4f9e23932e71d6c083b15f06c9109eab6eb50f20

Add prefix and postfix options for the lens name

view details

Jean-Philippe Cugnet

commit sha fc91fbbda5789a1f574675086aacd035f5f17108

Use the Keep a Changelog format

view details

Jean-Philippe Cugnet

commit sha d13f188b32eb4fbdd611dca9ac9fc8a3cee364b1

Update the development environment

view details

Jean-Philippe Cugnet

commit sha 5aeb7d0174764ad6a6cb2b23482e51346230ff8c

[CI] Update the configuration and use ex_check

view details

Jean-Philippe Cugnet

commit sha 58d3d189258510dbcc112cdb75390cee60fceb79

Update the Credo configuration

view details

Jean-Philippe Cugnet

commit sha 23d625bc5daaa8291a10eea699aa5e84e510184d

Update the dependencies (from my local offline hex.pm mirror)

view details

Jean-Philippe Cugnet

commit sha 77d90ddb881e16ec743fc6da94a71ecc5f1a1b17

Write the documentation

view details

Jean-Philippe Cugnet

commit sha c4ad71a78f78b5101b02b7dc0f0c5bfb4289ee1d

Bump the version to 0.1.0

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 77d90ddb881e16ec743fc6da94a71ecc5f1a1b17

Write the documentation

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 23d625bc5daaa8291a10eea699aa5e84e510184d

Update the dependencies (from my local offline hex.pm mirror)

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 58d3d189258510dbcc112cdb75390cee60fceb79

Update the Credo configuration

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha d13f188b32eb4fbdd611dca9ac9fc8a3cee364b1

Update the development environment

view details

Jean-Philippe Cugnet

commit sha 5aeb7d0174764ad6a6cb2b23482e51346230ff8c

[CI] Update the configuration and use ex_check

view details

push time in a month

create barnchejpcmac/typed_struct_legacy_reflection

branch : release/1.0.0

created branch time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha ead6520f54ec1a5c59e66fcc9bd3e1fef123942e

Update the documentation

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha 0332994174d3586dd1ce44a4013904844329f906

Update the Credo configuration

view details

Jean-Philippe Cugnet

commit sha 789cb6115f1a8d31752b7f2dbbaf79cd5ff83675

Update typed_struct to branch release/0.2.0

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha b13b9cbee48dd2de6459f94ed3f588d812204970

Update the development environment

view details

Jean-Philippe Cugnet

commit sha ded24ef950c9d9760f4bfb951fdbebc86feb0a3f

[CI] Update the configuration and use ex_check

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 72f407abc9e1478dbfb280d957ed949cc15dbbc2

Update the changelog

view details

Jean-Philippe Cugnet

commit sha 9acc3a4c1c5864d68975a22a5657bbcad0e8ac40

Update the Copyright

view details

push time in a month

create barnchejpcmac/typed_struct

branch : release/0.2.0

created branch time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 427e4802232442351f2ccf64322d5c39aa2d11ed

Update the Credo configuration

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha a343ca23e606e7bb2d0ab833414687de90793176

Update the dependencies (from my local offline hex.pm mirror)

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 491311388b8f3a10754f3a377d3015201b57cef3

Few cosmetic changes in the README.md

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha a779dc60fb697c646e7cb1e491464d80a70672a9

Update the README.md with plugins and roadmap

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha d56c253f77366a92d82b36b6cdb2abd6d73b5444

[CI] Fix a typo

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 5b1f54d4dc4f06e72bbc913f567f7a8714c25ed2

[CI] Check for unused dependencies in mix.lock

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 3e788df9578b6a4b313358133e4c3ecd49e986cb

[CI] Run checks on OTP 23

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha ff6e19f83eef2e94b6e1b21a692f4dd113330877

[CI] Simplify the build matrix

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha ff94e778a69be1da3f95d25bdd29ae5d726ffe96

[CI] Add Elixir 1.9, 1.10 and OTP 22

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 91d33142fe963db1db5ad01561d34e67a95482ec

Update the development environment

view details

push time in a month

push eventejpcmac/confkit

Jean-Philippe Cugnet

commit sha 4a838d1d2fab11f088c77b3eb83ab1bc205360ba

[Zsh/Elixir] Add mck for mix check

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha f7f31a6008385434d5802b34880d3942c57bdcc2

[CI] Run the formatter only for last Elixir version

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha e63632a0b2c9af08c7aabc482249e8a64175362b

[CI] Use ex_check to run static analysers

view details

push time in a month

startedjepsen-io/jepsen

started time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 5038e7905d1df646552245cb5a6d6c7098011221

Update the changelog

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha fc91fbbda5789a1f574675086aacd035f5f17108

Use the Keep a Changelog format

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha 0623f7966c3ab2719cfd6de68fbc466fd140916d

Use the Keep a Changelog format

view details

push time in a month

push eventejpcmac/typed_struct

Jean-Philippe Cugnet

commit sha 726b69769b870c2e17e1b26450f11e2d36e5b569

Use the Keep a Changelog format

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha c89601a46aad7cb448ea0fc273afcf58493704f7

Use the Keep a Changelog format

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha 5a5a7c5a2e17244880b85b0938568dda87e434cd

Use the Keep a Changelog format

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 9f2a0e2f35f156303eeaf8d99cdb1d6ea410dce9

Use the Keep a Changelog format

view details

push time in a month

push eventejpcmac/typed_struct_legacy_reflection

Jean-Philippe Cugnet

commit sha f2a3a86512d95b0a2186df199fe272166184c883

[CI] Fix the configuration with Dialyxir 1.0.0-rc.7

view details

Jean-Philippe Cugnet

commit sha 5b18b4c75d5acecfd552b63361c29a9e4e3d124f

Use the Keep a Changelog format

view details

push time in a month

issue openedejpcmac/xgen

Use the keep a changelog format

Standards are good: https://keepachangelog.com/en/1.0.0/

created time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha 4f9e23932e71d6c083b15f06c9109eab6eb50f20

Add prefix and postfix options for the lens name

view details

push time in a month

push eventejpcmac/typed_struct_lens

Jean-Philippe Cugnet

commit sha ce1499e8533c33ea1ec90dca8085e6c50c03ea59

Implement the plugin

view details

push time in a month

issue commentejpcmac/typed_struct

Remove built-in reflection support

The plugin is available here.

ejpcmac

comment created time in a month

more