Skip to content

Commit

Permalink
Explain macro
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun committed Dec 17, 2024
1 parent 9652a15 commit 8a50648
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lavinmq/metadata.cr
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ module LavinMQ
end

private def fetch(path : Symbol | String, &default : -> Value)
# The macto will generate a case statement that matches "paths" to values in
# the wrapped namedtuple structure.
# For NamedTupleMetaData.new({a: {b: 1, c: "foo"}}) the generated
# statement will look like:
#
# case path
# when "a", :"a"
# if value = @data[:a]
# return Value.new(value)
# end
# return Value.nil
# when "a.b", :"a.b"
# if value = @data[:a][:b]
# return Value.new(value)
# end
# return Value.nil
# when "a.b.c", :"a.b.c"
# if value = @data[:a][:b][:c]
# return Value.new(value)
# end
# return Value.nil
# else
# yield
# end
#
{% begin %}
{%
paths = [] of Array(String)
Expand Down

0 comments on commit 8a50648

Please sign in to comment.