jobify 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68c0e9df1850d8df3ffd79918d74a14b8c5269b1e546107af418b04770032e42
4
- data.tar.gz: e1414b2383e972103a9808401a077fc05eead62d35661f99339cb857a9e5052b
3
+ metadata.gz: befabb328f9f8f32e568d4042eea00aa168159e586a8b536ebe461fd534cc356
4
+ data.tar.gz: 6e5a56168fd43ce015f2859108ea51f57440c3b71422c5ff6d2f4c56e290cbc8
5
5
  SHA512:
6
- metadata.gz: a9fce3c64c0b07da031c0c8cc47394920b272f5dc96a1a8e0bd0e3d9bc3b5f3217eecc04fbaf19a1ee69b77cb594bcddadc617e781140065f9f4b2d4c0e340b2
7
- data.tar.gz: f9d835f57374eec52d20902055ad5fc21cadcf58d8b0bff107a206912b19213f28ba676086e510334b745bb2960250a290781d267135da8d5ec3a1017f28d5d1
6
+ metadata.gz: 5f14cc62d1e8cf7aa53635d1ce346cd10b4a1949d959295489b9e0a86d461fed9165f42ed36965292356fa93d8bd7c1f7bbb7652cca8daca76ace6d5e38386cd
7
+ data.tar.gz: 3928441745d55e247e45c398b14688d8926dd49d1c3e01fb4ff972e3346b3e489ec367ad47cef8e6e1f60e7095067184cd5dc35139e0b535642d1ad9582fcdc8
data/.rubocop.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+ SuggestExtensions: false
3
5
  Exclude:
4
6
  - 'test/*'
5
7
 
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jobify (0.1.0)
4
+ jobify (0.2.0)
5
5
  activejob
6
6
  activesupport
7
7
 
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jobify
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
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: "perform_#{method_name}_later")
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 = method_name.to_s
27
+ method_name = method_name.to_s
28
+ job_method_name = job_method_name(method_name, job_method_name)
28
29
 
29
- if method_defined?(method_name) && !@jobified_methods[:instance][method_name]
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._define_job_class(method_name, job_method_name, params, singleton_method)
43
- job_class_name = singleton_method ? "JobifyClassMethod_#{method_name}_Job" : "JobifyInstanceMethod_#{method_name}_Job"
44
- parent_class = defined?(ApplicationJob) ? ApplicationJob : ActiveJob::Base
45
- job_class = Class.new(parent_class)
46
- caller_class = self
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.1.1
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-26 00:00:00.000000000 Z
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: