jobify 0.1.1 → 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 +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/jobify.gemspec +41 -0
- data/lib/jobify/version.rb +1 -1
- data/lib/jobify.rb +25 -15
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: befabb328f9f8f32e568d4042eea00aa168159e586a8b536ebe461fd534cc356
|
4
|
+
data.tar.gz: 6e5a56168fd43ce015f2859108ea51f57440c3b71422c5ff6d2f4c56e290cbc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f14cc62d1e8cf7aa53635d1ce346cd10b4a1949d959295489b9e0a86d461fed9165f42ed36965292356fa93d8bd7c1f7bbb7652cca8daca76ace6d5e38386cd
|
7
|
+
data.tar.gz: 3928441745d55e247e45c398b14688d8926dd49d1c3e01fb4ff972e3346b3e489ec367ad47cef8e6e1f60e7095067184cd5dc35139e0b535642d1ad9582fcdc8
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,3 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
8
8
|
|
9
9
|
## [0.1.0] - 2022-10-25
|
10
10
|
- Initial release
|
11
|
+
|
12
|
+
## [0.2.0] - 2022-10-27
|
13
|
+
- Add support for my_method?
|
14
|
+
- Add support for my_method!
|
15
|
+
- Allow POROs with same-name class and instance methods to jobify class methods
|
data/Gemfile.lock
CHANGED
data/jobify.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/jobify/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jobify"
|
7
|
+
spec.version = Jobify::VERSION
|
8
|
+
spec.authors = ["Søren Houen"]
|
9
|
+
spec.email = ["s@houen.net"]
|
10
|
+
|
11
|
+
spec.summary = "Turn any method into a background job (`jobify :hello_world` generates `def perform_hello_world_later`"
|
12
|
+
spec.homepage = "https://github.com/houen/jobify"
|
13
|
+
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/houen/jobify"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/houen/jobify/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
spec.add_dependency "activejob"
|
36
|
+
spec.add_dependency "activesupport"
|
37
|
+
|
38
|
+
# For more information and examples about making a new gem, check out our
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
41
|
+
end
|
data/lib/jobify/version.rb
CHANGED
data/lib/jobify.rb
CHANGED
@@ -17,33 +17,43 @@ module Jobify
|
|
17
17
|
|
18
18
|
included do
|
19
19
|
@jobified_methods = {
|
20
|
-
instance:
|
20
|
+
instance: {},
|
21
21
|
singleton: {}
|
22
22
|
}
|
23
23
|
|
24
|
-
def self.jobify(method_name, job_method_name:
|
24
|
+
def self.jobify(method_name, job_method_name: nil)
|
25
25
|
raise "method name cannot be blank" if method_name.blank?
|
26
26
|
|
27
|
-
method_name
|
27
|
+
method_name = method_name.to_s
|
28
|
+
job_method_name = job_method_name(method_name, job_method_name)
|
28
29
|
|
29
|
-
if
|
30
|
+
if respond_to?(method_name) && !@jobified_methods[:singleton][method_name]
|
31
|
+
# Class methods are jobified first,
|
32
|
+
# so that class methods can be jobified by POROs with same-name instance methods
|
33
|
+
params = method(method_name).parameters
|
34
|
+
_define_job_class(method_name, job_method_name, params, singleton_method: true)
|
35
|
+
@jobified_methods[:singleton][method_name] = true
|
36
|
+
elsif method_defined?(method_name) && !@jobified_methods[:instance][method_name]
|
30
37
|
# Instance method
|
31
38
|
params = instance_method(method_name).parameters
|
32
|
-
_define_job_class(method_name, job_method_name, params, false)
|
39
|
+
_define_job_class(method_name, job_method_name, params, singleton_method: false)
|
33
40
|
@jobified_methods[:instance][method_name] = true
|
34
|
-
elsif respond_to?(method_name) && !@jobified_methods[:singleton][method_name]
|
35
|
-
# Singleton method (Class method)
|
36
|
-
params = method(method_name).parameters
|
37
|
-
_define_job_class(method_name, job_method_name, params, true)
|
38
|
-
@jobified_methods[:singleton][method_name] = true
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
def self.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def self.job_method_name(method_name, job_method_name)
|
45
|
+
return method_name unless job_method_name.nil?
|
46
|
+
return "perform_#{method_name[0..-2]}_later?" if method_name.end_with?('?')
|
47
|
+
return "perform_#{method_name[0..-2]}_later!" if method_name.end_with?('!')
|
48
|
+
"perform_#{method_name}_later"
|
49
|
+
end
|
50
|
+
|
51
|
+
def self._define_job_class(method_name, job_method_name, params, singleton_method:)
|
52
|
+
method_name_for_class_constant = method_name.gsub('?', '_question_').gsub('!', '_bang_')
|
53
|
+
job_class_name = singleton_method ? "JobifyClassMethod_#{method_name_for_class_constant}_Job" : "JobifyInstanceMethod_#{method_name_for_class_constant}_Job"
|
54
|
+
parent_class = defined?(ApplicationJob) ? ApplicationJob : ActiveJob::Base
|
55
|
+
job_class = Class.new(parent_class)
|
56
|
+
caller_class = self
|
47
57
|
const_set(job_class_name, job_class)
|
48
58
|
|
49
59
|
# Define perform method on job class
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jobify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Søren Houen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
|
+
- jobify.gemspec
|
55
56
|
- lib/jobify.rb
|
56
57
|
- lib/jobify/version.rb
|
57
58
|
- sig/jobify.rbs
|
@@ -63,6 +64,7 @@ metadata:
|
|
63
64
|
homepage_uri: https://github.com/houen/jobify
|
64
65
|
source_code_uri: https://github.com/houen/jobify
|
65
66
|
changelog_uri: https://github.com/houen/jobify/CHANGELOG.md
|
67
|
+
rubygems_mfa_required: 'true'
|
66
68
|
post_install_message:
|
67
69
|
rdoc_options: []
|
68
70
|
require_paths:
|