Skip to content

Commit

Permalink
Fix context pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielpra1 committed Jul 25, 2019
1 parent b2edfd1 commit 40d3012
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/context_functions_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,26 @@ defmodule ContextFunctionsGenerator do

def generate_function(:update, name, _pluralized_name, module, opts) do
quote do
def unquote(:"update_#{name}")(%module{} = struct, attrs) do
def unquote(:"update_#{name}")(%unquote(module){} = struct, attrs) do
struct
|> unquote(module).unquote(opts[:update])(attrs)
|> alias!(Repo).update()
end

def unquote(:"update_#{name}!")(%module{} = struct, attrs) do
def unquote(:"update_#{name}!")(%unquote(module){} = struct, attrs) do
struct
|> unquote(module).unquote(opts[:update])(attrs)
|> alias!(Repo).update!()
end

def unquote(:"update_#{name}_with_assocs")(%module{} = struct, attrs, assocs) do
def unquote(:"update_#{name}_with_assocs")(%unquote(module){} = struct, attrs, assocs) do
struct
|> alias!(Repo).preload(assocs)
|> unquote(module).unquote(opts[:update])(attrs)
|> alias!(Repo).update()
end

def unquote(:"update_#{name}_with_assocs!")(%module{} = struct, attrs, assocs) do
def unquote(:"update_#{name}_with_assocs!")(%unquote(module){} = struct, attrs, assocs) do
struct
|> alias!(Repo).preload(assocs)
|> unquote(module).unquote(opts[:update])(attrs)
Expand All @@ -158,14 +158,14 @@ defmodule ContextFunctionsGenerator do

def generate_function(:delete, name, _pluralized_name, module, opts) do
quote do
def unquote(:"delete_#{name}")(%module{} = struct) do
def unquote(:"delete_#{name}")(%unquote(module){} = struct) do
struct
|> Ecto.Changeset.change()
|> check_assocs(unquote(opts[:check_constraints_on_delete]))
|> alias!(Repo).delete()
end

def unquote(:"delete_#{name}!")(%module{} = struct) do
def unquote(:"delete_#{name}!")(%unquote(module){} = struct) do
struct
|> Ecto.Changeset.change()
|> check_assocs(unquote(opts[:check_constraints_on_delete]))
Expand Down

0 comments on commit 40d3012

Please sign in to comment.