Last active
April 12, 2016 10:49
-
-
Save pikender/cb43c04937fbb95b289bfa43d8dfab08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/product.ex b/product.ex | |
index 25efbae..21632ff 100644 | |
--- a/product.ex | |
+++ b/product.ex | |
@@ -1,3 +1,6 @@ | |
+## Library Code | |
+## Defines DSL to be used by Service Code | |
+## in order to get properly consumed by Consumer | |
defmodule Nectar.ModelExtension do | |
defmacro __using__(_opts) do | |
quote do | |
@@ -7,6 +10,7 @@ defmodule Nectar.ModelExtension do | |
end | |
end | |
+ # Part of Schema Addition DSL | |
defmacro add_to_schema([do: block]) do | |
schema_change = Macro.escape(block) | |
quote bind_quoted: [schema_change: schema_change] do | |
@@ -23,16 +27,22 @@ defmodule Nectar.ModelExtension do | |
end | |
end | |
+## Service Code | |
defmodule Nectar.ExtendProduct do | |
+ ## Makes DSL available defined in library code | |
use Nectar.ModelExtension | |
add_to_schema do: (field :special, :boolean, virtual: true) | |
+ add_to_schema do: (field :type, :string, virtual: true) | |
end | |
defmodule Nectar.Product do | |
+ ## Make Service Code available to be consumed | |
+ ## through Library Code | |
import Nectar.ExtendProduct | |
schema do | |
+ ## Service Consumer Code | |
extensions | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment