delayable 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 22a499788c4598447f63ea0521c8db9c4fd31a6d63a1e823b756a9de205fdb42
4
+ data.tar.gz: 556ff5cd6ff684adf1fcc2f84a2ff3840693697972308eba74c415e0b23ff4ad
5
+ SHA512:
6
+ metadata.gz: 74ab9e694fecfb0324d41335cec0d429d1b1e0428b529627ade623dbd60ed7917dd5d7c1cfcda2548892bf54a1ea69e0d7639fb26cfa71dccdb4640e3c1392a7
7
+ data.tar.gz: 38e2c5cae56572f314b0c4572da14e4052092f037722cd90f03f03109ebc016898bf4a7a9fd5019a5750da693ad021a96f17984cbbc169646b6a6bbf4dfeea9d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2023 Trae Robrock
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Delayable
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "delayable"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install delayable
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/setup"
2
+
3
+ load "rails/tasks/statistics.rake"
4
+
5
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Delayable
2
+ VERSION = "0.2.0"
3
+ end
data/lib/delayable.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "delayable/version"
2
+
3
+ module Delayable
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ def delay(method_name, class_method: false, wait: nil, limits_concurrency: nil, queue: :default)
8
+ job = const_set(delayable_job_name(method_name, class_method:),
9
+ delayable_job_class(method_name, class_method:, concurrency_limits: limits_concurrency, queue:))
10
+
11
+ defined_wait = wait
12
+ delayable_define_method(class_method:, method_name:) do |*arguments, **kwargs|
13
+ wait = kwargs.key?(:wait) ? kwargs.delete(:wait) : defined_wait
14
+ run_data = { current_attributes: Current.attributes, record: self }
15
+ job.set(wait:).perform_later(run_data, *arguments, **kwargs)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def delayable_job_class(method_name, class_method: false, concurrency_limits: nil, queue: :default)
22
+ klass = self
23
+ Class.new(ApplicationJob) do
24
+ queue_as queue
25
+
26
+ limits_concurrency(**concurrency_limits) if concurrency_limits.is_a?(Hash)
27
+
28
+ define_method(:perform) do |run_data = {}, *arguments, **kwargs|
29
+ Current.set(run_data[:current_attributes] || {}) do
30
+ (class_method ? klass : run_data[:record]).__send__(method_name, *arguments, **kwargs)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def delayable_job_name(method_name, class_method: false)
37
+ :"#{'Class' if class_method}#{method_name.to_s.camelize}Job"
38
+ end
39
+
40
+ def delayable_define_method(class_method:, method_name:, &block)
41
+ define_method_type = class_method ? :define_singleton_method : :define_method
42
+ public_send(define_method_type, "#{method_name}_later", &block)
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delayable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Trae Robrock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.4.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.4.3
27
+ description: https://github.com/trobrock/delayable
28
+ email:
29
+ - trobrock@gmail.com
30
+ - andrew.katz@hey.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/delayable.rb
39
+ - lib/delayable/version.rb
40
+ homepage: https://github.com/trobrock/delayable
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ allowed_push_host: https://rubygems.org
45
+ homepage_uri: https://github.com/trobrock/delayable
46
+ source_code_uri: https://github.com/trobrock/delayable.git
47
+ changelog_uri: https://github.com/trobrock/delayable/CHANGELOG.md
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.5.16
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: https://github.com/trobrock/delayable
67
+ test_files: []