anachronic 0.42.4 → 0.43.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 552a86cd15eb48eaf95c7e44b5a06d291e2d1cf9382361022cf7bce823affa26
4
- data.tar.gz: cd0cd75050e84005456221f679831e3973b337595a6586cefe82c32574ca6577
3
+ metadata.gz: 9906018bb2d13cdcc3f754250c50b66ce7934ac7c913e8f8b7184ddd205b2746
4
+ data.tar.gz: 890c2ed316e9a6256a5a3f02892c5f261067a6fd2900e070d4e61dfcc9db59e3
5
5
  SHA512:
6
- metadata.gz: 6ddb8926f83f9610b726a63ffed96d87452820cbd491c6358d9407c835801a41267063d801b302c828dcdf16aeb36d0835f49b1fd8e672225a422e2e7a78fe6c
7
- data.tar.gz: e066bc7cf579c026b633fb53ce039b82201783a561a14eea61f7cf82e7500c40086e0b5e7694e45e7ad8f7d9000d00ba6a819dd88868482e64c5a760cb6da4e8
6
+ metadata.gz: 3b380edb644cca69d4305b70e0a95549d73868c46ec2283c7c6c1ad6bdf7cbf19f7d8e887fd26809ffd1dc501dbddccfd439c7052188b57d3d84baa8617e4f60
7
+ data.tar.gz: fdfc6ba786e0a255bfbb376f1e9919093936711394021eb03b617f838740417b4ccda031f7f4a425ae55c9d1eb0a244867ec3aba3fe0697b02a14e25ef7b0b88
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.4)
4
+ anachronic (0.43.2)
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
 
data/Rakefile CHANGED
@@ -1,7 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
5
3
 
6
4
  RSpec::Core::RakeTask.new(:spec)
7
5
 
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'anachronic/version'
4
- require 'anachronic/error'
5
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,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'anachronic/error'
4
+ require 'anachronic/executors/sidekiq'
5
+ require 'anachronic/executors/application_job'
6
+ require 'anachronic/executors/resque'
7
+
3
8
  module Anachronic
9
+ # Class for deciding a background execution backend
4
10
  class BackgroundExecutor
5
11
  class << self
6
12
  def call(instance, method, *args)
@@ -12,14 +18,19 @@ module Anachronic
12
18
  private
13
19
 
14
20
  def executor
15
- return Executors::ApplicationJob if defined?(ApplicationJob)
16
- return Executors::ApplicationJob if defined?(Sidekiq)
21
+ @executor ||= begin
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)
25
+ end
26
+ end
17
27
 
18
- Executors::Resque if defined?(Resque)
28
+ def default_or_defined?(name)
29
+ defined?(name) || config.default_executor == name
19
30
  end
20
31
 
21
32
  def no_executor
22
- raise Anachronic::Error, 'No background executor defined, async methods will be executed synchronously'
33
+ raise Anachronic::Error('No background executor found')
23
34
  end
24
35
  end
25
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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anachronic
4
- VERSION = '0.42.4'
4
+ VERSION = '0.43.2'
5
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.4
4
+ version: 0.43.2
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