Skip to content

Commit 30f3d09

Browse files
committed
place extension
1 parent dac6587 commit 30f3d09

5 files changed

Lines changed: 138 additions & 2 deletions

File tree

lib/diffo/provider/components/place/extension.ex

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,99 @@ defmodule Diffo.Provider.Place.Extension do
1313
See the [DSL cheat sheet](DSL-Diffo.Provider.Place.Extension.html) for the full DSL reference.
1414
See `Diffo.Provider.BasePlace` for full usage documentation.
1515
"""
16-
use Spark.Dsl.Extension, sections: []
16+
@instance_role %Spark.Dsl.Entity{
17+
name: :role,
18+
describe: "Declares a role this Place kind plays with respect to Instances",
19+
target: Diffo.Provider.Place.Extension.InstanceRole,
20+
args: [:role, :instance_type],
21+
schema: [
22+
role: [
23+
type: :atom,
24+
required: true,
25+
doc: "The role name, an atom"
26+
],
27+
instance_type: [
28+
type: :any,
29+
doc: "The module of the related Instance resource"
30+
]
31+
]
32+
}
33+
34+
@party_role %Spark.Dsl.Entity{
35+
name: :role,
36+
describe: "Declares a role this Place kind plays with respect to Parties",
37+
target: Diffo.Provider.Place.Extension.PartyRole,
38+
args: [:role, :party_type],
39+
schema: [
40+
role: [
41+
type: :atom,
42+
required: true,
43+
doc: "The role name, an atom"
44+
],
45+
party_type: [
46+
type: :any,
47+
doc: "The module of the related Party resource"
48+
]
49+
]
50+
}
51+
52+
@place_role %Spark.Dsl.Entity{
53+
name: :role,
54+
describe: "Declares a role this Place kind plays with respect to other Places",
55+
target: Diffo.Provider.Place.Extension.PlaceRole,
56+
args: [:role, :place_type],
57+
schema: [
58+
role: [
59+
type: :atom,
60+
required: true,
61+
doc: "The role name, an atom"
62+
],
63+
place_type: [
64+
type: :any,
65+
doc: "The module of the related Place resource"
66+
]
67+
]
68+
}
69+
70+
@instances %Spark.Dsl.Section{
71+
name: :instances,
72+
describe: "Declares the roles this Place kind plays with respect to Instances",
73+
examples: [
74+
"""
75+
instances do
76+
role :site_for, MyApp.AccessService
77+
end
78+
"""
79+
],
80+
entities: [@instance_role]
81+
}
82+
83+
@parties %Spark.Dsl.Section{
84+
name: :parties,
85+
describe: "Declares the roles this Place kind plays with respect to Parties",
86+
examples: [
87+
"""
88+
parties do
89+
role :home_of, MyApp.Organization
90+
end
91+
"""
92+
],
93+
entities: [@party_role]
94+
}
95+
96+
@places %Spark.Dsl.Section{
97+
name: :places,
98+
describe: "Declares the roles this Place kind plays with respect to other Places",
99+
examples: [
100+
"""
101+
places do
102+
role :within, MyApp.GeographicSite
103+
end
104+
"""
105+
],
106+
entities: [@place_role]
107+
}
108+
109+
use Spark.Dsl.Extension,
110+
sections: [@instances, @parties, @places]
17111
end

lib/diffo/provider/components/place/extension/info.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
defmodule Diffo.Provider.Place.Extension.Info do
66
use Spark.InfoGenerator,
77
extension: Diffo.Provider.Place.Extension,
8-
sections: []
8+
sections: [:instances, :parties, :places]
99

1010
@doc "Returns true if the module is a BasePlace-derived resource"
1111
@spec place?(module()) :: boolean()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2025 diffo contributors <https://github.com/diffo-dev/diffo/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule Diffo.Provider.Place.Extension.InstanceRole do
6+
@moduledoc """
7+
InstanceRole - DSL entity declaring a role this Place kind plays with respect to Instances
8+
"""
9+
defstruct [:role, :instance_type, __spark_metadata__: nil]
10+
11+
defimpl String.Chars do
12+
def to_string(struct), do: inspect(struct)
13+
end
14+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2025 diffo contributors <https://github.com/diffo-dev/diffo/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule Diffo.Provider.Place.Extension.PartyRole do
6+
@moduledoc """
7+
PartyRole - DSL entity declaring a role this Place kind plays with respect to Parties
8+
"""
9+
defstruct [:role, :party_type, __spark_metadata__: nil]
10+
11+
defimpl String.Chars do
12+
def to_string(struct), do: inspect(struct)
13+
end
14+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2025 diffo contributors <https://github.com/diffo-dev/diffo/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule Diffo.Provider.Place.Extension.PlaceRole do
6+
@moduledoc """
7+
PlaceRole - DSL entity declaring a role this Place kind plays with respect to other Places
8+
"""
9+
defstruct [:role, :place_type, __spark_metadata__: nil]
10+
11+
defimpl String.Chars do
12+
def to_string(struct), do: inspect(struct)
13+
end
14+
end

0 commit comments

Comments
 (0)