Skip to content

Instantly share code, notes, and snippets.

@rachid
Created January 12, 2016 13:54
Show Gist options
  • Save rachid/432f1e3bece359653939 to your computer and use it in GitHub Desktop.
Save rachid/432f1e3bece359653939 to your computer and use it in GitHub Desktop.
defp from_model(resource) when is_map(resource) do
resource.__struct__
|> extract
end
defp from_model(resource) do
resource
|> extract
end
defp extract(resource) do
resource
|> Mix.Utils.underscore
|> String.split("/")
|> List.last
|> to_string
end
@rachid
Copy link
Author

rachid commented Jan 12, 2016

om nog cleaner in de module de externals importeren

import String,    only: [split: 2]
import Mix.Utils, only: [underscore: 1]
import List,      only: [last: 1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment