Skip to content

Commit 20d8bc0

Browse files
committed
event
1 parent d3f8ef3 commit 20d8bc0

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/diffo/helpers/util.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,20 @@ defmodule Diffo.Util do
402402
end
403403
end
404404

405+
@doc """
406+
Nest values from list of tuples into a list, with a new tuple key
407+
## Examples
408+
iex> list = [state: :up, weeks: 1, days: 5]
409+
iex> Diffo.Util.nest(list, [:weeks, :days], :duration)
410+
iex>
411+
[state: :up, duration: [weeks: 1, days: 5]]
412+
413+
"""
414+
def nest(list, tuple_keys, new_tuple_key) when is_list(list) and is_list(tuple_keys) do
415+
{nested_list, remainder_list} = Enum.split_with(list, fn {tuple_key, _} -> tuple_key in tuple_keys end)
416+
set(remainder_list, new_tuple_key, nested_list)
417+
end
418+
405419
defimpl Jason.Encoder, for: Tuple do
406420
def encode(tuple, _opts) when is_tuple(tuple) do
407421
tuple

lib/diffo/provider.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,17 @@ defmodule Diffo.Provider do
215215
define :update_entity_ref, action: :update
216216
define :delete_entity_ref, action: :destroy
217217
end
218+
219+
resource Diffo.Provider.Event do
220+
define :create_event, action: :create
221+
define :get_event_by_id, action: :read, get_by: :id
222+
define :list_events, action: :list
223+
224+
define :list_events_by_instance_id,
225+
action: :list_events_by_instance_id,
226+
args: [:instance_id]
227+
228+
define :delete_event, action: :destroy
229+
end
218230
end
219231
end

0 commit comments

Comments
 (0)