generic_job 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +31 -0
- data/lib/generic_job/async.rb +17 -0
- data/lib/generic_job/perform.rb +49 -0
- data/lib/generic_job/stub.rb +60 -0
- data/lib/generic_job.rb +12 -0
- data/lib/tasks/generic_job_tasks.rake +6 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47fd8f208d252ee6488a5eb70f08754bb724d34dffa4985c54091e83c0b3b0fb
|
4
|
+
data.tar.gz: e2903438690596f195d96340f662e338d30dfdc0b9a449489c10ca9aeab568de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cda3b8537772be5734c2d1b555a1ed56d986b3bb078700cb1591f5648b529d0da78eb4bf6642eda0d926e6f969ec6789a5971405a47ea05e7c55ef879ea61eb7
|
7
|
+
data.tar.gz: d1d9426119cdc58a42f2fef240202a9107589d24f8f30de6b564ddec09fa22b7271def3dff2cc45a81bae73e6fe1eea80e17eb73a7ddb3f3bf08cc548f9cdc8e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Zbigniew Humeniuk
|
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
|
+
# GenericJob
|
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 'generic_job'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install generic_job
|
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,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'GenericJob'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
require 'bundler/gem_tasks'
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
|
25
|
+
Rake::TestTask.new(:test) do |t|
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
task default: :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GenericJob
|
4
|
+
module Async
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def async opts = {}
|
9
|
+
GenericJob::Stub.new self, opts
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def async opts = {}
|
14
|
+
GenericJob::Stub.new self, opts
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GenericJob
|
4
|
+
module Perform
|
5
|
+
def perform receiver, data
|
6
|
+
case receiver
|
7
|
+
when Hash
|
8
|
+
handle_passed_hash receiver.symbolize_keys, data
|
9
|
+
when String
|
10
|
+
handle_passed_obj receiver.constantize, data
|
11
|
+
else
|
12
|
+
handle_passed_obj receiver, data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def fetch_receiver hash
|
19
|
+
if hash[:init_args]
|
20
|
+
hash[:class].constantize.new(*to_array(hash[:init_args]))
|
21
|
+
else
|
22
|
+
hash[:class].constantize
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def handle_passed_hash hash, meth
|
27
|
+
if hash[:meth_args]
|
28
|
+
fetch_receiver(hash).send meth, *to_array(hash[:meth_args])
|
29
|
+
else
|
30
|
+
fetch_receiver(hash).send meth
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_passed_obj obj, data
|
35
|
+
case data
|
36
|
+
when String
|
37
|
+
obj.send data
|
38
|
+
when Hash
|
39
|
+
args = data[:args] || [data[:arg]]
|
40
|
+
obj.send data[:meth], *args
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_array args
|
45
|
+
return args if args.is_a? Array
|
46
|
+
[args]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GenericJob
|
4
|
+
class Stub
|
5
|
+
def initialize receiver, opts
|
6
|
+
@receiver = receiver
|
7
|
+
@opts = opts
|
8
|
+
@init_args = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def respond_to_missing? name, include_private
|
12
|
+
receiver_has_method?(name) || super
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing name, *args, &_block
|
16
|
+
if receiver_has_method? name
|
17
|
+
call_missing_method name.to_s, *args
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def new *args
|
24
|
+
@init_args = args
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def receiver_has_method? name
|
31
|
+
if @init_args
|
32
|
+
@receiver.new(*@init_args).respond_to? name
|
33
|
+
else
|
34
|
+
@receiver.respond_to? name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def call_missing_method name, *args
|
39
|
+
if @init_args
|
40
|
+
GenericJob.set(@opts).perform_later receiver_as_hash(args), name
|
41
|
+
else
|
42
|
+
GenericJob.set(@opts)
|
43
|
+
.perform_later prepare_receiver, meth: name, args: args
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def receiver_as_hash args
|
48
|
+
{
|
49
|
+
class: @receiver.name,
|
50
|
+
init_args: @init_args,
|
51
|
+
meth_args: args
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def prepare_receiver
|
56
|
+
return @receiver unless @receiver.is_a? Class
|
57
|
+
@receiver.name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/generic_job.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: generic_job
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zbigniew Humeniuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-05 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: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sqlite3
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Run instance and class methods in the background jobs with ease.
|
48
|
+
email:
|
49
|
+
- hello@artofcode.co
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/generic_job.rb
|
58
|
+
- lib/generic_job/async.rb
|
59
|
+
- lib/generic_job/perform.rb
|
60
|
+
- lib/generic_job/stub.rb
|
61
|
+
- lib/tasks/generic_job_tasks.rake
|
62
|
+
homepage: https://artofcode.co
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.7.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Higher level abstraction on the top of ActiveJob.
|
86
|
+
test_files: []
|