async_block 0.1.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: 4d70c1e318e02f7736120722c8ddbc30f9a56e6e942fae325d1e91b12e4247d5
4
+ data.tar.gz: f99cf81d5070831b83d94a0f8d0697379e45ee22c67a0bb2a4013f33ebb334f1
5
+ SHA512:
6
+ metadata.gz: e82800cefee5fa047163b798bae63b235fea5de4bbb52e418a66bc04c15e1fe56ae4327e92f0b5b905ca5d7a5023f7237551524a1e5a40a10c0a7464e62926f0
7
+ data.tar.gz: 8b5d737d3d3a2fba34224579db48fb6550ca60b40e44ede72992d512de63ebe0a641c8597735eab3fcba8faef037e844b12c654db47a1d80321dbdb74fe758ec
data/.DS_Store ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-12-11
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 ichbinadittyadey@gmail.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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in async_block.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
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,52 @@
1
+ # AsyncBlock
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/async_block`. 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 async_block
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install async_block
16
+
17
+ ## Usage
18
+
19
+ ```
20
+ AsyncBlock.perform_async do
21
+ puts('This is running in a temporary job')
22
+ puts('Put your code below')
23
+ end
24
+ ```
25
+
26
+ To put some delay on the async execution (say 5 minutes):
27
+ ```
28
+ AsyncBlock.perform_with_delay(5.minutes) do
29
+ puts('This is running in a temporary job')
30
+ puts('Put your code below')
31
+ end
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To build gem locally, run `gem build`
39
+
40
+ 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).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/async_block. 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]/async_block/blob/master/CODE_OF_CONDUCT.md).
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
49
+
50
+ ## Code of Conduct
51
+
52
+ Everyone interacting in the AsyncBlock project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/async_block/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/async_block/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'async_block'
7
+ spec.version = AsyncBlock::VERSION
8
+ spec.authors = ['Adittya Dey']
9
+ spec.email = ['ichbinadittyadey@gmail.com']
10
+
11
+ spec.summary = 'A rails code block to write asynchronous code.'
12
+ spec.description = 'A usable code block for rails to run your code asynchronusly, "\
13
+ "this will help in preventing writing of new jobs to run smaller pieces of code.'
14
+ spec.homepage = 'https://github.com/Velocity-Engineering/async-block'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = '>= 2.6.0'
17
+
18
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
19
+
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+
22
+ spec.metadata['homepage_uri'] = spec.homepage
23
+ spec.metadata['source_code_uri'] = spec.homepage
24
+ spec.metadata['changelog_uri'] = spec.homepage
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(__dir__) do
29
+ `git ls-files -z`.split("\x0").reject do |f|
30
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
31
+ end
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ # Uncomment to register a new dependency of your gem
38
+ spec.add_dependency 'activesupport', ['>= 3.0', '< 8.0']
39
+ spec.add_dependency 'ruby2ruby', '~> 2.5.0'
40
+
41
+ # For more information and examples about making a new gem, check out our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'block_source_service'
4
+
5
+ module AsyncBlock
6
+ # Job to dynamically run a block of code
7
+ class AsyncWrapperJob < ActiveJob::Base
8
+ queue_as :async_wrapper_job
9
+
10
+ def perform(block_string)
11
+ block = str_to_block(block_string)
12
+ execute_block!(block)
13
+ end
14
+
15
+ private
16
+
17
+ def str_to_block(block_string)
18
+ SourceToBlock.new(block_string).convert
19
+ end
20
+
21
+ def execute_block!(block)
22
+ block&.call
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'ruby2ruby'
5
+ require 'ruby_parser'
6
+
7
+ module AsyncBlock
8
+ # BlockToSource - converts code block to source string
9
+ # this will help in preventing writing of new jobs to run smaller pieces of code
10
+ #
11
+ # The following full app-like example demonstrates how to use the BlockToSource
12
+ #
13
+ # block_string = BlockToSource.new(block).convert
14
+ class BlockToSource
15
+ def initialize(block)
16
+ @block = block
17
+ end
18
+
19
+ def convert
20
+ block_to_str
21
+ end
22
+
23
+ private
24
+
25
+ def block_to_str
26
+ @block&.to_ruby
27
+ end
28
+ end
29
+
30
+ # SourceToBlock - converts source string to code block
31
+ # this will help in preventing writing of new jobs to run smaller pieces of code
32
+ #
33
+ # The following full app-like example demonstrates how to use the SourceToBlock
34
+ #
35
+ # block = BlockToSource.new(block_string).convert
36
+ # block&.call
37
+ class SourceToBlock
38
+ def initialize(block_string)
39
+ @block_string = block_string
40
+ end
41
+
42
+ def convert
43
+ str_to_block
44
+ end
45
+
46
+ private
47
+
48
+ def str_to_block
49
+ instance_eval("lambda { #{@block_string} }", __FILE__, __LINE__)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AsyncBlock
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'async_block/version'
4
+ require_relative 'async_block/block_source_service'
5
+ require_relative 'async_block/async_wrapper_job'
6
+
7
+ # AsyncBlock - A usable code block for rails to run your code asynchronusly,
8
+ # this will help in preventing writing of new jobs to run smaller pieces of code
9
+ #
10
+ # The following full app-like example demonstrates how to use the AsyncBlock
11
+ #
12
+ # AsyncBlock.perform_async do
13
+ # puts('This is running in a temporary job')
14
+ # puts('Put your code below')
15
+ # end
16
+ #
17
+ # To put some delay on the async execution (say 5 minutes):
18
+ # AsyncBlock.perform_with_delay(5.minutes) do
19
+ # puts('This is running in a temporary job')
20
+ # puts('Put your code below')
21
+ # end
22
+ module AsyncBlock
23
+ class Error < StandardError; end
24
+
25
+ def self.perform_async(&block)
26
+ block_string = BlockToSource.new(block).convert
27
+ AsyncWrapperJob.perform_later(block_string)
28
+ end
29
+
30
+ def self.perform_with_delay(delay, &block)
31
+ block_string = BlockToSource.new(block).convert
32
+ AsyncWrapperJob.set(wait: delay).perform_later(block_string)
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module AsyncBlock
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async_block
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Adittya Dey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '8.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '8.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby2ruby
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.5.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.5.0
47
+ description: |-
48
+ A usable code block for rails to run your code asynchronusly, "\
49
+ "this will help in preventing writing of new jobs to run smaller pieces of code.
50
+ email:
51
+ - ichbinadittyadey@gmail.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - ".DS_Store"
57
+ - CHANGELOG.md
58
+ - CODE_OF_CONDUCT.md
59
+ - Gemfile
60
+ - LICENSE.txt
61
+ - README.md
62
+ - Rakefile
63
+ - async_block.gemspec
64
+ - lib/async_block.rb
65
+ - lib/async_block/async_wrapper_job.rb
66
+ - lib/async_block/block_source_service.rb
67
+ - lib/async_block/version.rb
68
+ - sig/async_block.rbs
69
+ homepage: https://github.com/Velocity-Engineering/async-block
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ allowed_push_host: https://rubygems.org
74
+ homepage_uri: https://github.com/Velocity-Engineering/async-block
75
+ source_code_uri: https://github.com/Velocity-Engineering/async-block
76
+ changelog_uri: https://github.com/Velocity-Engineering/async-block
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.6.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.1.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A rails code block to write asynchronous code.
96
+ test_files: []