trailblazer-workflow 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 283a1522c88d9c93033fab7b877cf9dab734938e74acbe642ff1883ab87b7f67
4
+ data.tar.gz: 25bf599330db478cf5aa6e7212aad1929340755d9161d9ccdd011fae3fec1318
5
+ SHA512:
6
+ metadata.gz: 0d677ba9af3834f39dc8bf5f3475a3c47dd24a5948e70547216f5ec7301bead4888bba285fc04a7a3e646c9036bc0337545a82b38928a801275b692b9d1b0e9a
7
+ data.tar.gz: ebd402fe46b5044c2b8aebdfa919658df30a0b7fe0e0df3fed9a5d8294d9fdec855fe61d0c3217118895dedfd9edbee1dcefc8b7f99bd8d66c1d99dd10ae947c
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.01.] - 2023-06-04
2
+
3
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in trailblazer-workflow.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Trailblazer::Workflow
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/trailblazer/workflow`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add trailblazer-workflow
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install trailblazer-workflow
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/trailblazer-workflow.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,95 @@
1
+ require "representable/json"
2
+ require "ostruct"
3
+ require "trailblazer/macro"
4
+
5
+ module Trailblazer
6
+ module Workflow
7
+ # Computes a {Intermediate} data structures for every lane from a TRB PRO/editor .json file.
8
+ class Generate < Trailblazer::Activity::Railway
9
+ Element = Struct.new(:id, :type, :data, :links, :label)
10
+ Link = Struct.new(:target_id, :semantic)
11
+
12
+ module Representer
13
+ class Collaboration < Representable::Decorator # Called {structure}.
14
+ include Representable::JSON
15
+
16
+ property :id
17
+ collection :lanes, class: OpenStruct do
18
+ property :id
19
+ collection :elements, class: Element do
20
+ property :id
21
+ property :label
22
+ property :type,
23
+ parse_filter: ->(fragment, options) { fragment.to_sym }
24
+ property :data #, default: {}
25
+ collection :links, class: Link do
26
+ property :target_id
27
+ property :semantic,
28
+ parse_filter: ->(fragment, options) { fragment.to_sym }
29
+ end
30
+ end
31
+ end
32
+ collection :messages
33
+ end
34
+ end # Representer
35
+
36
+ def self.transform_from_json(ctx, json_document:, parser: Representer::Collaboration, **)
37
+ ctx[:structure] = parser.new(OpenStruct.new).from_json(json_document) # DISCUSS: this could be sitting in PRO?
38
+ end
39
+
40
+ def lanes(ctx, structure:, **)
41
+ structure.lanes
42
+ end
43
+
44
+ def self.find_start_event(ctx, lane:, **)
45
+ ctx[:start_event] = lane.elements.find { |el| el.id == "Start" }
46
+ end
47
+
48
+ # DISCUSS: do we "want" this, should we handle that in the export/convert code and create some Start event?
49
+ def self.default_start_event(ctx, lane:, **)
50
+ ctx[:start_event] = lane.elements[0]
51
+ end
52
+
53
+ def self.compute_termini_map(ctx, lane:, **)
54
+ terminus_nodes = lane.elements
55
+ .find_all { |node| node.type == :terminus }
56
+ .collect { |node| [node.id, node.id.to_sym] } # {"success" => :success}
57
+
58
+ suspend_nodes = lane.elements
59
+ .find_all { |node| node.type == :suspend }
60
+ .collect { |node| [node.id, :suspend] }
61
+
62
+ ctx[:termini_map] = (terminus_nodes + suspend_nodes).to_h
63
+ end
64
+
65
+ def self.compile_intermediate(ctx, lane:, start_event:, termini_map:, **)
66
+ wirings = lane.elements.collect do |node|
67
+ [
68
+ Activity::Schema::Intermediate.TaskRef(node.id, (node.data || {}).merge(type: node.type)),
69
+
70
+ node.links.collect do |link|
71
+ Activity::Schema::Intermediate.Out(link.semantic, link.target_id)
72
+ end
73
+ ]
74
+ end.to_h
75
+
76
+ intermediate = Activity::Schema::Intermediate.new(
77
+ wirings,
78
+ termini_map, # {"success"=>:success, "suspend-d15ef8ea-a55f-4eed-a0e8-37f717d21c2f"=>:suspend}
79
+ start_event.id # start
80
+ )
81
+
82
+ ctx[:value] = [lane.id, intermediate]
83
+ end
84
+
85
+ step Generate.method(:transform_from_json), id: :transform_from_json
86
+ step Each(dataset_from: :lanes, item_key: :lane, collect: true) {
87
+ step Generate.method(:find_start_event), id: :find_start_event
88
+ fail Generate.method(:default_start_event), id: :default_start_event,
89
+ Output(:success) => Track(:success)
90
+ step Generate.method(:compute_termini_map), id: :compute_termini_map
91
+ step Generate.method(:compile_intermediate), id: :compute_intermediate
92
+ }, Out() => ->(ctx, collected_from_each:, **) { {intermediates: collected_from_each.to_h} } #{:collected_from_each => :intermediates}
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trailblazer
4
+ module Workflow
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "workflow/version"
4
+
5
+ module Trailblazer
6
+ module Workflow
7
+ # Your code goes here...
8
+ end
9
+ end
10
+
11
+ require "trailblazer/workflow/generate"
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trailblazer-workflow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Sutterer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trailblazer-developer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.17
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.17
27
+ - !ruby/object:Gem::Dependency
28
+ name: representable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: trailblazer-macro
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-line
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - apotonick@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - lib/trailblazer/workflow.rb
95
+ - lib/trailblazer/workflow/generate.rb
96
+ - lib/trailblazer/workflow/version.rb
97
+ homepage: https://trailblazer.to/2.1/docs/workflow
98
+ licenses:
99
+ - LGPL-3.0
100
+ metadata:
101
+ homepage_uri: https://trailblazer.to/2.1/docs/workflow
102
+ source_code_uri: https://github.com/trailblazer/trailblazer-workflow
103
+ changelog_uri: https://github.com/trailblazer/trailblazer-workflow/blob/master/CHANGES.md
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 2.6.0
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.2.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: BPMN process engine
123
+ test_files: []