Closed d-mart closed 8 years ago
What if we keep a counter module attribute a used that counter instead of a random string?
π― βοΈ π π :shipit:
I tried that (and maybe wrongly) but couldn't access @module_attributes
inside of macro things
defp interpret_opts(options, name) do
@counter (@counter + 1)
unique_string = @counter |> Integer.to_string
......
== Compilation error on file lib/exhal/transcoder.ex ==
** (ArgumentError) cannot set attribute @counter inside function/macro
(elixir) lib/kernel.ex:2314: Kernel.do_at/4
(elixir) expanding macro: Kernel.@/1
lib/exhal/transcoder.ex:182: ExHal.Transcoder.interpret_opts/2
:ets
table at compile time?
ducks
Any inklings of a merge sometime soon?
Released as 5.1.0
When using a param name twice in a transcoder, like so:
And then trying to encode a document:
The resulting document lacks properties based off the same parameter after the first one:
This comes from the
@injectors
and@extractors
being built programmatically from theparam
name, then accumulated into the respective module variable. When looking through the@injectors
or@extractors
at run-time, the same (identical) one is found each time. This leads, in this case, to"hello"
being added to the document once, then overwritten the second time. And the second property is not generated. Or something like thatThe change herein adds some uniqueness to the
injector_name
andextractor_name
. There are undoubtedly better ways to do this, but in general this approach works.Alternatively, it might work to pass the property
name
intoExHal.Transcoder.interpret_opts
and generate the injector names that way. Those should be unique as well.