petri-dsl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +21 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +10 -0
- data/lib/petri/net.rb +42 -0
- data/lib/petri/place.rb +26 -0
- data/lib/petri/transition.rb +56 -0
- data/lib/petri/version.rb +3 -0
- data/lib/petri.rb +8 -0
- data/petri-dsl.gemspec +26 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f2e766fe17ad24973f882bf0abbc8ccc4fb1e194099da69c1b8eeba5127b923b
|
4
|
+
data.tar.gz: 86df851c947b96f4b262e62e7e9d8e911a68ad10e49585b5e578d7ae41a69718
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c396c291a966d3d6c396c5d190e85f56870336d0f11240f9e8e4c74f316f652397013c52589f4a0d2e61686a71ae1275982980affb07f8018aa91750c29d58b
|
7
|
+
data.tar.gz: cc374b930af65407d31c2139049679fc359f7d7c721924375ef89b6489e14377553278d1b28992e3be86ce9a6deefd16997fc0723b20c3c457aa689250924d70
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dsh0416@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
petri-dsl (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.14.0)
|
10
|
+
rake (12.3.3)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
minitest (~> 5.0)
|
17
|
+
petri-dsl!
|
18
|
+
rake (~> 12.0)
|
19
|
+
|
20
|
+
BUNDLED WITH
|
21
|
+
2.1.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Delton Ding
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Petri::Dsl
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'petri-dsl'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install petri-dsl
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'petri'
|
23
|
+
|
24
|
+
network = Petri::Net.new do |net|
|
25
|
+
net.start_place :start, name: 'Start'
|
26
|
+
net.end_place :end, name: 'End'
|
27
|
+
|
28
|
+
net.transition :leader_evaluate, name: 'Leader Evaluate', consume: :start do |t|
|
29
|
+
t.produce :leader_approved, name: 'Leader Approved', with_guard: :approved
|
30
|
+
t.produce :rejected, name: 'Rejected', with_guard: :rejected
|
31
|
+
end
|
32
|
+
|
33
|
+
net.transition :hr_evaluate, name: 'HR Evaluate', consume: :leader_approved do |t|
|
34
|
+
t.produce :hr_approved, name: 'HR Approved', with_guard: :approved
|
35
|
+
t.produce :rejected, with_guard: :rejected
|
36
|
+
end
|
37
|
+
|
38
|
+
net.transition :report_back, name: 'Report Back', consume: :hr_approved, produce: :end
|
39
|
+
|
40
|
+
net.transition :resend_request, name: 'Resend Request', consume: :rejected do |t|
|
41
|
+
t.produce :start, with_guard: :resend
|
42
|
+
t.produce :end, with_guard: :discard
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
puts network.compile
|
47
|
+
|
48
|
+
# {:places=>[{:label=>:start, :name=>"Start"}, {:label=>:end, :name=>"End"}, {:label=>:leader_approved, :name=>"Leader Approved"}, {:label=>:rejected, :name=>"Rejected"}, {:label=>:hr_approved, :name=>"HR Approved"}], :transitions=>[{:label=>:leader_evaluate, :name=>"Leader Evaluate", :consume=>[:start], :produce=>[{:label=>:leader_approved, :guard=>:approved}, {:label=>:rejected, :guard=>:rejected}]}, {:label=>:hr_evaluate, :name=>"HR Evaluate", :consume=>[:leader_approved], :produce=>[{:label=>:hr_approved, :guard=>:approved}, {:label=>:rejected, :guard=>:rejected}]}, {:label=>:report_back, :name=>"Report Back", :consume=>[:hr_approved], :produce=>[{:label=>:end, :guard=>nil}]}, {:label=>:resend_request, :name=>"Resend Request", :consume=>[:rejected], :produce=>[{:label=>:start, :guard=>:resend}, {:label=>:end, :guard=>:discard}]}], :start_place=>:start, :end_place=>:end}
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/petri-dsl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/petri-dsl/blob/master/CODE_OF_CONDUCT.md).
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
59
|
+
|
60
|
+
## Code of Conduct
|
61
|
+
|
62
|
+
Everyone interacting in the Petri::Dsl project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/petri-dsl/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/petri/net.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
class Petri::Net
|
2
|
+
def initialize(options={}, &block)
|
3
|
+
@places = []
|
4
|
+
@transitions = []
|
5
|
+
@start = nil
|
6
|
+
@end = nil
|
7
|
+
block.call(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_place(place, options={})
|
11
|
+
entity = place if place.is_a? Petri::Place
|
12
|
+
entity = Petri::Place.new(place, options)
|
13
|
+
|
14
|
+
@places << entity unless @places.include?(entity)
|
15
|
+
entity
|
16
|
+
end
|
17
|
+
|
18
|
+
def start_place(label, options={})
|
19
|
+
place = add_place(label, options)
|
20
|
+
@start = place.label
|
21
|
+
end
|
22
|
+
|
23
|
+
def end_place(label, options={})
|
24
|
+
place = add_place(label, options)
|
25
|
+
@end = place.label
|
26
|
+
end
|
27
|
+
|
28
|
+
def transition(label, options={}, &block)
|
29
|
+
raise TypeError unless label.is_a? Symbol
|
30
|
+
raise ArgumentError if @transitions.include? label
|
31
|
+
@transitions << Petri::Transition.new(self, label, options, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def compile
|
35
|
+
{
|
36
|
+
places: @places.map { |place| place.compile },
|
37
|
+
transitions: @transitions.map { |transition| transition.compile },
|
38
|
+
start_place: @start,
|
39
|
+
end_place: @end,
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
data/lib/petri/place.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class Petri::Place
|
2
|
+
attr_reader :label, :name
|
3
|
+
def initialize(label, options={})
|
4
|
+
raise TypeError unless label.is_a? Symbol
|
5
|
+
|
6
|
+
name = options[:name] || label.to_s
|
7
|
+
raise TypeError unless name.is_a? String
|
8
|
+
|
9
|
+
@label = label
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def compile
|
14
|
+
{
|
15
|
+
label: @label,
|
16
|
+
name: @name,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def eql?(other)
|
21
|
+
return @label == other.label if other.is_a? Petri::Place
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :==, :eql?
|
26
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Petri::Transition
|
2
|
+
attr_reader :label, :name, :consumption, :production
|
3
|
+
|
4
|
+
def initialize(net, label, options={}, &block)
|
5
|
+
raise TypeError unless net.is_a? ::Petri::Net
|
6
|
+
@net = net
|
7
|
+
|
8
|
+
raise TypeError unless label.is_a? Symbol
|
9
|
+
@label = label
|
10
|
+
|
11
|
+
@name = options[:name] || label.to_s
|
12
|
+
raise TypeError unless name.is_a? String
|
13
|
+
|
14
|
+
@consumption = []
|
15
|
+
@production = []
|
16
|
+
|
17
|
+
consume(options[:consume]) unless options[:consume].nil?
|
18
|
+
produce(options[:produce]) unless options[:produce].nil?
|
19
|
+
|
20
|
+
block.call(self) unless block.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def consume(label, options={})
|
24
|
+
@net.add_place(label, options)
|
25
|
+
@consumption << label if label.is_a? Symbol
|
26
|
+
if label.is_a? Array
|
27
|
+
for place in label
|
28
|
+
raise TypeError unless place.is_a? Symbol
|
29
|
+
@consumption << place
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def produce(label, options={})
|
35
|
+
@net.add_place(label, options)
|
36
|
+
raise TypeError unless (options[:with_guard].is_a? Symbol or options[:with_guard].nil?)
|
37
|
+
guard = options[:with_guard]
|
38
|
+
|
39
|
+
@production << {label: label, guard: guard} if label.is_a? Symbol
|
40
|
+
if label.is_a? Array
|
41
|
+
for place in label
|
42
|
+
raise TypeError unless place.is_a? Symbol
|
43
|
+
@production << {label: label, guard: guard}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def compile
|
49
|
+
{
|
50
|
+
label: @label,
|
51
|
+
name: @name,
|
52
|
+
consume: @consumption,
|
53
|
+
produce: @production,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
data/lib/petri.rb
ADDED
data/petri-dsl.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/petri/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "petri-dsl"
|
5
|
+
spec.version = Petri::VERSION
|
6
|
+
spec.authors = ["Delton Ding"]
|
7
|
+
spec.email = ["dsh0416@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = ""
|
10
|
+
spec.description = ""
|
11
|
+
spec.homepage = "https://github.com/dsh0416/petri-dsl"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/dsh0416/petri-dsl"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: petri-dsl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Delton Ding
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ''
|
14
|
+
email:
|
15
|
+
- dsh0416@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/petri.rb
|
29
|
+
- lib/petri/net.rb
|
30
|
+
- lib/petri/place.rb
|
31
|
+
- lib/petri/transition.rb
|
32
|
+
- lib/petri/version.rb
|
33
|
+
- petri-dsl.gemspec
|
34
|
+
homepage: https://github.com/dsh0416/petri-dsl
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://github.com/dsh0416/petri-dsl
|
39
|
+
source_code_uri: https://github.com/dsh0416/petri-dsl
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.1.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: ''
|
59
|
+
test_files: []
|