-
Notifications
You must be signed in to change notification settings - Fork 18
Handle UUID's as path values #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5258527
7e75558
0cbd37b
af95fa6
6d732b5
e6496ff
45fa649
e9002da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,5 @@ cache: | |
| directories: | ||
| - _build | ||
| - deps | ||
| notifications: | ||
| email: false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ defmodule EctoMaterializedPath.Path do | |
| """ | ||
|
|
||
| def cast(list) when is_list(list) do | ||
| path_is_correct? = Enum.all?(list, fn(path_id) -> is_integer(path_id) end) | ||
| path_is_correct? = Enum.all?(list, fn(path_id) -> (is_integer(path_id) || is_binary(path_id)) end) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please write an option to and add a few lines to the doc
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx for the feedback, I like the way you want it to do. what I'm struggling (Elixir noob) is how to access the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have to figure out by yourself. I don't have a time right now :( Use SO/elixir forum to get it and write according to my feedback
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. |
||
|
|
||
| if path_is_correct? do | ||
| { :ok, list } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,15 @@ defmodule EctoMaterializedPath.PathTest do | |
| assert Path.cast([13, 45, 18]) == { :ok, [13, 45, 18] } | ||
| end | ||
|
|
||
| test "passes with UUID's" do | ||
| assert Path.cast(["38432046-4351-4676-8988-10f0262da113", "a65ce828-52f2-4931-8719-9f7d97723f3b"]) == { :ok, ["38432046-4351-4676-8988-10f0262da113", "a65ce828-52f2-4931-8719-9f7d97723f3b"] } | ||
| end | ||
|
|
||
| test "fails with random value" do | ||
| assert Path.cast(4) == :error | ||
| end | ||
|
|
||
| test "fails with wrongs path" do | ||
| assert Path.cast([14, "ee", 45]) == :error | ||
| assert Path.cast([14, [:ok], 45]) == :error | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move condition check to the new line, it'll be easier to read. Plus, make it looks better.
Depending on
id_typeoption provided inuse, check for either uuid or regular. Create a private function for each. Foruuid, please use an Ecto default functionality.