anachronic 0.42.3 → 0.43.1

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: 743dddfad60bed6e4675cdac3331ea6ec4bfbb0f56ad9ebfc704b2a9e43a2d2c
4
- data.tar.gz: 543760bbdff7016978b015e5488441f41751c1822f45708921d21b44ead3d202
3
+ metadata.gz: c47a036f9c454bc2d3611bb5112971aced6ffb11ec19cd52c4395f9a65de15a2
4
+ data.tar.gz: 1e0cca89c7fa62548050133dfbf1fd57b6d2e3a86d69b4f4d5aac55a580a8bd1
5
5
  SHA512:
6
- metadata.gz: d977775a046b882d476d9d2a03c3a63b962787c931b152cde5a17b06b18db765a2e50e51aaca3be61102d1ee080ab689b704040ff3daf2db807c78526b00e9d5
7
- data.tar.gz: df029c59826a30b9f41a932aec5141b6cd1f120e9d7193b968dc2d5fbf0643b5c3771732fcf91a23c040eab25e44a6fbe28884bfa85a67928756892d104a176b
6
+ metadata.gz: c4c0b3344d175039caaff2c8376efdb564f110727761c1c9a230d872346bdd95bb837f4b7d6c7f440a366c2bee3ab78bafadce1fc99abd107576ab079f49146a
7
+ data.tar.gz: 6453409497e03fa1504992b25f47ef8caffc8945f03587d338e9f43175aab33320d3ad4792d1a223e0dd5d02e3a4880b58e90605b52666ab1c501cffdf48b46f
data/.gitignore CHANGED
@@ -6,6 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ *.gem
10
10
  # rspec failure tracking
11
11
  .rspec_status
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- anachronic (0.42.3)
4
+ anachronic (0.43.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.4.4)
9
+ diff-lcs (1.3)
10
10
  rake (12.3.3)
11
- rspec (3.9.0)
12
- rspec-core (~> 3.9.0)
13
- rspec-expectations (~> 3.9.0)
14
- rspec-mocks (~> 3.9.0)
15
- rspec-core (3.9.2)
16
- rspec-support (~> 3.9.3)
17
- rspec-expectations (3.9.2)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.3)
18
18
  diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.9.0)
20
- rspec-mocks (3.9.1)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.9.0)
23
- rspec-support (3.9.3)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
data/README.md CHANGED
@@ -50,9 +50,21 @@ Or install it yourself as:
50
50
 
51
51
  $ gem install anachronic
52
52
 
53
- ## Usage
53
+ ## Configuration
54
+
55
+ To configure, run this or add to an initializers file (in case of Rails)
56
+
57
+ ```ruby
58
+ Anachronic.configure do |config|
59
+ config.default_executor = Sidekiq
60
+ end
61
+ ```
62
+
63
+ In case no `default_exeucutor` is configured, the gem will use the first one that is available (defined) from the list:
64
+ - Sidekiq
65
+ - ApplicationJob
66
+ - Resque
54
67
 
55
- TODO: Write usage instructions here
56
68
 
57
69
  ## Development
58
70
 
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "anachronic/version"
4
- require "anachronic/background_executor"
5
- require "anachronic/error"
3
+ require 'anachronic/version'
4
+ require 'anachronic/background_executor'
5
+ require 'anachronic/error'
6
+ require 'anachronic/override'
7
+ require 'anachronic/configuration'
6
8
 
7
9
  module Anachronic
8
- def async(method_name)
9
- new_name = "anachronic__#{method_name}".to_sym
10
- alias_method new_name, method_name
11
-
12
- define_method(method_name) do |*args|
13
- BackgroundExecutor.call(self, new_name, *args)
14
- end
15
- end
10
+ include Override
11
+ include Configuration
16
12
  end
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './error.rb'
4
+ require_relative './executors/sidekiq.rb'
5
+ require_relative './executors/application_job.rb'
6
+ require_relative './executors/resque.rb'
4
7
 
5
8
  module Anachronic
9
+ # Class for deciding a background execution backend
6
10
  class BackgroundExecutor
7
11
  class << self
8
12
  def call(instance, method, *args)
@@ -15,14 +19,18 @@ module Anachronic
15
19
 
16
20
  def executor
17
21
  @executor ||= begin
18
- return Executors::ApplicationJob if defined?(ApplicationJob)
19
- return Executors::ApplicationJob if defined?(Sidekiq)
20
- return Executors::Resque if defined?(Resque)
22
+ return Executors::Sidekiq if default_or_defined?(Sidekiq)
23
+ return Executors::ApplicationJob if default_or_defined?(ApplicationJob)
24
+ return Executors::Resque if default_or_defined?(Resque)
21
25
  end
22
26
  end
23
27
 
28
+ def default_or_defined?(name)
29
+ defined?(name) || config.default_executor == name
30
+ end
31
+
24
32
  def no_executor
25
- raise Anachronic::Error('No background executor defined, async methods will be executed synchronously')
33
+ raise Anachronic::Error('No background executor found')
26
34
  end
27
35
  end
28
36
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module Anachronic
6
+ module Configuration
7
+ def self.configure
8
+ @config ||= OpenStruct.new
9
+ yield(@config) if block_given?
10
+ @config
11
+ end
12
+
13
+ def self.config
14
+ @config || configure
15
+ end
16
+ end
17
+ end
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anachronic
4
- module Executors
5
- class ApplicationJob
6
- def self.call(instance, method, *args)
4
+ module Executors
5
+ # Default executor for ApplicationJob backend
6
+ class ApplicationJob
7
+ class << self
8
+ def call(instance, method, *args)
7
9
  default_executor.perform_later(instance, method, *args)
8
10
  end
9
11
 
10
- def self.default_executor
12
+ def default_executor
11
13
  @default_executor ||= begin
12
14
  Class.new(ApplicationJob) do
13
15
  def perform_later(instance, method, *args)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anachronic
4
+ # Takes over a method and renames original method for later use
5
+ module Override
6
+ def async(method_name)
7
+ new_name = "anachronic__#{method_name}".to_sym
8
+ alias_method new_name, method_name
9
+
10
+ undef_method method_name
11
+
12
+ define_method(method_name) do |*args|
13
+ BackgroundExecutor.call(self, new_name, *args)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Anachronic
2
- VERSION = '0.42.3'
4
+ VERSION = '0.43.1'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anachronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.42.3
4
+ version: 0.43.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danielius Visockas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-10 00:00:00.000000000 Z
11
+ date: 2020-12-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Removing boilerplate from async code
14
14
  email:
@@ -32,8 +32,10 @@ files:
32
32
  - bin/setup
33
33
  - lib/anachronic.rb
34
34
  - lib/anachronic/background_executor.rb
35
+ - lib/anachronic/configuration.rb
35
36
  - lib/anachronic/error.rb
36
37
  - lib/anachronic/executors/application_job.rb
38
+ - lib/anachronic/override.rb
37
39
  - lib/anachronic/version.rb
38
40
  homepage: https://github.com/dvisockas/anachronic
39
41
  licenses:
@@ -58,8 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
60
  - !ruby/object:Gem::Version
59
61
  version: '0'
60
62
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 2.7.8
63
+ rubygems_version: 3.1.4
63
64
  signing_key:
64
65
  specification_version: 4
65
66
  summary: Moving your method execution to the world of asynchronity