Skip to content

Commit

Permalink
Merge pull request stavro#92 from richeterre/master
Browse files Browse the repository at this point in the history
Accept both string and atom keys in cast/2 and dump/2
  • Loading branch information
stavro authored May 10, 2018
2 parents 02e0eb0 + b78245d commit f49207a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/arc_ecto/type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ defmodule Arc.Ecto.Type do
def type, do: :string

@filename_with_timestamp ~r{^(.*)\?(\d+)$}

# Support embeds_one/embeds_many

def cast(definition, %{file_name: file, updated_at: updated_at}) do
cast(definition, %{"file_name" => file, "updated_at" => updated_at})
end

def cast(_definition, %{"file_name" => file, "updated_at" => updated_at}) do
{:ok, %{file_name: file, updated_at: updated_at}}
end
Expand Down Expand Up @@ -51,4 +54,8 @@ defmodule Arc.Ecto.Type do
gsec = :calendar.datetime_to_gregorian_seconds(NaiveDateTime.to_erl(updated_at))
{:ok, "#{file_name}?#{gsec}"}
end

def dump(definition, %{"file_name" => file_name, "updated_at" => updated_at}) do
dump(definition, %{file_name: file_name, updated_at: updated_at})
end
end

0 comments on commit f49207a

Please sign in to comment.