-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
we can render generated/state_table.rb.
- Loading branch information
Showing
4 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Trailblazer | ||
module Workflow | ||
module Generate | ||
# State guards are code blocks defined by the user to allow/deny executing | ||
# a catch event. | ||
module StateGuards | ||
module_function | ||
|
||
def call(iteration_set, namespace:, **options) | ||
states = StateTable.aggregate_by_state(iteration_set) | ||
cli_rows = StateTable.render_data(states, **options) | ||
|
||
available_states = cli_rows.collect do |row| | ||
{ | ||
suggested_state_name: row["state name"], | ||
key: row[:catch_events].collect { |position| Present.id_for_position(position) }.uniq.sort | ||
} | ||
end | ||
|
||
# formatting, find longest state name. | ||
max_length = available_states.collect { |row| row[:suggested_state_name].inspect.length }.max | ||
|
||
state_guard_rows = available_states.collect do |row| | ||
id_snippet = %(, id: #{row[:key].inspect}) # TODO: move me to serializer code. | ||
|
||
%( #{row[:suggested_state_name].inspect.ljust(max_length)} => {guard: ->(ctx, process_model:, **) { raise "implement me!" }#{id_snippet}},) | ||
end.join("\n") | ||
|
||
snippet = %(#{namespace}::StateGuards = Trailblazer::Workflow::Collaboration::StateGuards.from_user_hash({ | ||
#{state_guard_rows} | ||
}) | ||
) | ||
end | ||
end | ||
end | ||
end # Generate | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Trailblazer | ||
module Workflow | ||
class Generate | ||
# state_table is a datastructure connecting the event label with the IDs | ||
# of the possible catch events, so we can retrieve the start positions. | ||
# | ||
# This generates app/concepts/posting/collaboration/generated/state_table.rb | ||
class StateTable < Trailblazer::Activity::Railway | ||
step Subprocess(Introspect::StateTable) | ||
step :render | ||
# Generate code stubs for a state table. | ||
|
||
def render(ctx, rows:, namespace:, **) | ||
available_states = rows.collect do |row| | ||
{ | ||
suggested_state_name: row["state name"], | ||
key: row[:catch_events].collect { |position| Introspect::Present.id_for_position(position) }.uniq.sort | ||
} | ||
end | ||
|
||
# formatting, find longest state name. | ||
max_length = available_states.collect { |row| row[:suggested_state_name].inspect.length }.max | ||
|
||
state_guard_rows = available_states.collect do |row| | ||
id_snippet = %(id: #{row[:key].inspect}) # TODO: move me to serializer code. | ||
|
||
%( #{row[:suggested_state_name].inspect.ljust(max_length)} => {#{id_snippet},) | ||
end.join("\n") | ||
|
||
snippet = %(# This file is generated by trailblazer-workflow. | ||
module #{namespace}::Generated | ||
StateTable = { | ||
#{state_guard_rows} | ||
} | ||
end | ||
) | ||
|
||
ctx[:snippet] = snippet | ||
end | ||
end | ||
end # Generate | ||
end | ||
end |
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
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