anachronic 0.42.7 → 0.43.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: 4461c6dcc692bc00a5a1206887182c095be2fc081ed065d58b8cb463750f2c21
4
- data.tar.gz: c1ce7c68f61900edb534d3e76ec78fff67a0cd86bcb99e1a8743a69b4320deb1
3
+ metadata.gz: 258ec036a2fdc3a3ef100b6e77b9db95f09b640138297cdefe8eb8120cb18bc7
4
+ data.tar.gz: f71aa8121e0a373044026d82b3ea654c67f47816aaca3645a99df8cfcac6d941
5
5
  SHA512:
6
- metadata.gz: df8e237a8230c563be2654cf506d54c51b725ec041274fd9f68e032cb1c6c57af04fc091fc3a8d2b5484b12ee55e98a9c263d8d31eaec24aa34ff56384aca3c6
7
- data.tar.gz: 45cdbf8e69e75da8481205adaefc84a45e3801e3cd177e552d67764a36082e87cd857a290c622738a22596001aec71a146bd0fa96c1e08a938fbe7f1503c9ca8
6
+ metadata.gz: 707d67121db58d16bfd44f504ebfd7d5ee234cab4824d1e42d71ede2cbe96649898c21404f8e21480e0d0a1a8f02a3415e214f2fffd03cde9b7ccd2ca1364e6f
7
+ data.tar.gz: 461deb146099ef7e3f97b9369be8f66229bd3503acc9fc6391257decc123f7d14c9626bd4bef291529ec33403bd6d278934166b427625f3d1d365003fe041c32
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- anachronic (0.42.7)
4
+ anachronic (0.43.0)
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
+ - ApplicationJob
65
+ - Sidekiq
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,17 +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'
6
- require 'anachronic/executors/application_job'
5
+ require 'anachronic/error'
6
+ require 'anachronic/override'
7
+ require 'anachronic/configuration'
7
8
 
8
9
  module Anachronic
9
- def async(method_name)
10
- new_name = "anachronic__#{method_name}".to_sym
11
- alias_method new_name, method_name
12
-
13
- define_method(method_name) do |*args|
14
- BackgroundExecutor.call(self, new_name, *args)
15
- end
16
- end
10
+ include Override
11
+ include Configuration
17
12
  end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './error.rb'
4
+
3
5
  module Anachronic
6
+ # Class for deciding a background execution backend
4
7
  class BackgroundExecutor
5
8
  class << self
6
9
  def call(instance, method, *args)
@@ -12,14 +15,19 @@ module Anachronic
12
15
  private
13
16
 
14
17
  def executor
15
- return Executors::ApplicationJob if defined?(ApplicationJob)
16
- return Executors::ApplicationJob if defined?(Sidekiq)
18
+ @executor ||= begin
19
+ return Executors::ApplicationJob if default_or_defined?(ApplicationJob)
20
+ return Executors::Sidekiq if default_or_defined?(Sidekiq)
21
+ return Executors::Resque if default_or_defined?(Resque)
22
+ end
23
+ end
17
24
 
18
- Executors::Resque if defined?(Resque)
25
+ def default_or_defined?(name)
26
+ defined?(name) || config.default_executor == name
19
27
  end
20
28
 
21
29
  def no_executor
22
- raise Anachronic::Error, 'No background executor defined, async methods will be executed synchronously'
30
+ raise Anachronic::Error('No background executor found')
23
31
  end
24
32
  end
25
33
  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
@@ -2,16 +2,19 @@
2
2
 
3
3
  module Anachronic
4
4
  module Executors
5
+ # Default executor for ApplicationJob backend
5
6
  class ApplicationJob
6
- def self.call(instance, method, *args)
7
- default_executor.perform_later(instance, method, *args)
8
- end
7
+ class << self
8
+ def call(instance, method, *args)
9
+ default_executor.perform_later(instance, method, *args)
10
+ end
9
11
 
10
- def self.default_executor
11
- @default_executor ||= begin
12
- Class.new(ApplicationJob) do
13
- def self.perform_later(instance, method, *args)
14
- instance.public_send(method, *args)
12
+ def default_executor
13
+ @default_executor ||= begin
14
+ Class.new(ApplicationJob) do
15
+ def perform_later(instance, method, *args)
16
+ instance.public_send(method, *args)
17
+ end
15
18
  end
16
19
  end
17
20
  end
@@ -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.7'
4
+ VERSION = '0.43.0'
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.7
4
+ version: 0.43.0
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