general_actor 0.1.2

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: '0984aa17a31cdc4029199d37efa3c17e525b2215623a0134ceb81f5f77ab2c03'
4
+ data.tar.gz: d820f2f798f4ff316e5f33e2de09d9c3e24596e2583c1c7badb1d9348393b718
5
+ SHA512:
6
+ metadata.gz: c8d159ff3a9c2421de4ea0e1ec2356e0d6f73b6994db82dd0a2b8dbb31c98e3a0c9996e2a0a461a2b6a69663d52555e2e762e60ce8c773fdb9a32a79bcabce76
7
+ data.tar.gz: e82f78e92a2f5109e084d58aef489145d4232243d6299c5a440983da0cebef8ba2f849add85439d85cdb849d7aefa73f6141557d1ab71917505160c56a6f0cd4
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0.0
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/MethodLength:
16
+ Max: 20
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-01-14
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at 55623006+umgefahren@users.noreply.github.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in general_actor.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "rbs", "~> 2.0.0"
15
+
16
+ gem "timeout"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Hannes
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # GeneralActor
2
+
3
+ An easy abstraction for an actor, written for Ruby 3.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'general_actor'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install general_actor
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ actor = GeneralActor::RactorActor.new ""
25
+
26
+ inp = "This is a value, we wont to set"
27
+
28
+ actor.value = inp # Set the value just in the actor
29
+
30
+ out = actor.value # Get the current value from the actor
31
+
32
+ inp == out # => True
33
+ ```
34
+
35
+ ## Development
36
+
37
+ 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.
38
+
39
+ 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).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/umgefahren/general_actor. 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]/general_actor/blob/master/CODE_OF_CONDUCT.md).
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
48
+
49
+ ## Code of Conduct
50
+
51
+ Everyone interacting in the GeneralActor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/general_actor/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
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
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GeneralActor
4
+ VERSION = "0.1.2"
5
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "general_actor/version"
4
+ require_relative "ractor_actor"
5
+
6
+ ##
7
+ # Module containing the ReactorActor and the general Actor.
8
+ module GeneralActor
9
+ class Error < StandardError; end
10
+ include ReactorActorM
11
+
12
+ ##
13
+ # This class represents the general implementation of an actor
14
+ class Actor
15
+ ##
16
+ # Initializes a new actor
17
+ def initialize(_obj)
18
+ raise "Just a template actor, use the implementations instead!"
19
+ end
20
+
21
+ ##
22
+ # Kill the actor
23
+ def kill; end
24
+
25
+ ##
26
+ # Get the value of the object stored in the actor
27
+ def value; end
28
+
29
+ ##
30
+ # Set the value of the object stored in the actor
31
+ def value=(value); end
32
+
33
+ def get_value_with_timeout(timeout); end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ module GeneralActor
2
+ class Error < StandardError
3
+ end
4
+
5
+ class GeneralActor[T]
6
+ def initialize: (obj: T) -> void
7
+ def kill: () -> void
8
+ def value: () -> T
9
+ def value=:(T) -> void
10
+ end
11
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require_relative "general_actor"
4
+
5
+ require "timeout"
6
+
7
+ module ReactorActorM
8
+ ##
9
+ # A shared state actor driven by Ruby Ractors.
10
+ class RactorActor
11
+ ##
12
+ # Internally used RactorMessage with Backchannel
13
+ class RactorMessage
14
+ def initialize(method, obj = nil)
15
+ @obj = Ractor.make_shareable obj, copy: true
16
+ @method = method
17
+ @backchannel = Ractor.new do
18
+ val = Ractor.recv
19
+ Ractor.yield val
20
+ end
21
+ end
22
+
23
+ attr_reader :obj, :method, :backchannel
24
+ end
25
+
26
+ private_constant :RactorMessage
27
+
28
+ def initialize(data)
29
+ @ractor = Ractor.new do
30
+ state = nil
31
+ loop do
32
+ incoming = Ractor.recv
33
+ case incoming.method
34
+ when :get
35
+ incoming.backchannel.send state
36
+ when :set
37
+ state = incoming.obj
38
+ incoming.backchannel.send true
39
+ when :kill
40
+ break
41
+ end
42
+ end
43
+ end
44
+
45
+ @ractor.send RactorMessage.new :set, data
46
+ _ = @value
47
+ end
48
+
49
+ def value
50
+ m = RactorMessage.new :get
51
+ @ractor.send m
52
+ m.backchannel.take
53
+ end
54
+
55
+ def value=(new_value)
56
+ m = RactorMessage.new :set, new_value
57
+ @ractor.send m
58
+ _ = m.backchannel.take
59
+ end
60
+
61
+ def get_value_with_timeout(timeout)
62
+ m = RactorMessage.new :get
63
+ @ractor.send m
64
+ val = nil
65
+ Timeout.timeout(timeout) do
66
+ val = m.backchannel.take
67
+ end
68
+ val
69
+ end
70
+
71
+ def kill
72
+ m = RactorMessage.new :kill
73
+ @ractor.send m
74
+ _ = m.backchannel.take
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,9 @@
1
+ module ReactorActorM
2
+ class RactorActor[T]
3
+ def initialize: (data: T) -> void
4
+ def kill: () -> void
5
+ def value: () -> T
6
+ def value=:(T) -> void
7
+ def get_value_with_timeout: (timeout: Timeout) -> T
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module GeneralActor
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: general_actor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Hannes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: timeout
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ description:
28
+ email:
29
+ - 55623006+umgefahren@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - lib/general_actor.rb
42
+ - lib/general_actor.rbs
43
+ - lib/general_actor/version.rb
44
+ - lib/ractor_actor.rb
45
+ - lib/ractor_actor.rbs
46
+ - sig/general_actor.rbs
47
+ homepage: https://github.com/umgefahren/general_actor
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/umgefahren/general_actor
52
+ source_code_uri: https://github.com/umgefahren/general_actor
53
+ changelog_uri: https://github.com/umgefahren/general_actor/blob/master/CHANGELOG.md
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.3.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: An abstraction over state managing actors
73
+ test_files: []