Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc72cf38

Browse files
authored
improvement: Adddescription option to Reactor DSL and struct. (#268)
1 parent94a2762 commitc72cf38

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

‎documentation/dsls/DSL-Reactor.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ The top-level reactor DSL
7777
| Name| Type| Default| Docs|
7878
|------|------|---------|------|
7979
|[`return`](#reactor-return){: #reactor-return }|`atom`|| Specify which step result to return upon completion.|
80+
|[`description`](#reactor-description){: #reactor-description }|`String.t`|| An optional description for the Reactor.|
8081

8182

8283
###reactor.middlewares

‎lib/reactor.ex‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ defmodule Reactor do
3737
"""
3838

3939
defstructcontext:%{},
40+
description:nil,
4041
id:nil,
4142
input_descriptions:%{},
4243
inputs:[],
@@ -136,6 +137,7 @@ defmodule Reactor do
136137

137138
@typet::%Reactor{
138139
context:context,
140+
description:nil|String.t(),
139141
id:any,
140142
input_descriptions:%{atom=>String.t()},
141143
inputs:[atom],

‎lib/reactor/dsl.ex‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ defmodule Reactor.Dsl do
2121
doc:"""
2222
Specify which step result to return upon completion.
2323
"""
24+
],
25+
description:[
26+
type::string,
27+
required:false,
28+
doc:"""
29+
An optional description for the Reactor.
30+
"""
2431
]
2532
],
2633
entities:[

‎lib/reactor/info.ex‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ defmodule Reactor.Info do
1616

1717
defto_struct(module)do
1818
with{:ok,reactor}<-entities_to_struct(module),
19-
{:ok,reactor}<-maybe_set_return(module,reactor)do
19+
{:ok,reactor}<-maybe_set_return(module,reactor),
20+
{:ok,reactor}<-maybe_set_description(module,reactor)do
2021
add_middleware(module,reactor)
2122
end
2223
end
@@ -53,6 +54,13 @@ defmodule Reactor.Info do
5354
end
5455
end
5556

57+
defpmaybe_set_description(module,reactor)do
58+
casereactor_description(module)do
59+
{:ok,value}whenbyte_size(value)>0->{:ok,%{reactor|description:value}}
60+
_->{:ok,reactor}
61+
end
62+
end
63+
5664
defpadd_middleware(module,reactor)do
5765
module
5866
|>reactor_middlewares()

‎test/reactor/dsl_test.exs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,21 @@ defmodule Reactor.DslTest do
166166
assertmiddlewares==[ExampleMiddleware]
167167
end
168168
end
169+
170+
describe"description"do
171+
test"descriptions can be added"do
172+
defmoduleDescribedReactordo
173+
useReactor
174+
175+
description"A reactor that does nothing useful"
176+
177+
step:noopdo
178+
runfn_,_->{:ok,:noop}end
179+
end
180+
end
181+
182+
assert"A reactor that does nothing useful"==
183+
DescribedReactor.reactor()|>Map.fetch!(:description)
184+
end
185+
end
169186
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp