resque_extensions 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,27 @@ require "resque_extensions/version"
4
4
  require "resque_extensions/async_method"
5
5
 
6
6
  module ResqueExtensions
7
+
8
+ # Whether or not we should be running
9
+ # asynchronously
10
+ def self.async
11
+ # if we have never set @async, we default
12
+ # to true
13
+ if @async.nil?
14
+ @async = true
15
+ end
16
+ return @async
17
+ end
18
+
19
+ # Whether or not we should be running asynchronously
20
+ #
21
+ # @example
22
+ # ResqueExtensions.async = false
23
+ # MyInstance.async(:do_something) # => calls synchronously
24
+ #
25
+ def self.async=(new_val)
26
+ @async = new_val
27
+ end
7
28
 
8
29
  def self.enqueue_class_method(klass, *args)
9
30
  klass = "#{AsyncMethod::CLASS_PREFIX}#{klass}"
@@ -13,7 +34,12 @@ module ResqueExtensions
13
34
  module ObjectMethods
14
35
  # call this method asynchronously
15
36
  def async(*args)
16
- ResqueExtensions::AsyncMethod.new(self, *args).enqueue!
37
+ if ResqueExtensions.async == true
38
+ ResqueExtensions::AsyncMethod.new(self, *args).enqueue!
39
+ # just call inline
40
+ else
41
+ self.send(*args)
42
+ end
17
43
  end
18
44
  end
19
45
  end
@@ -35,6 +35,8 @@ module ResqueExtensions
35
35
  @caller.is_a?(Class)
36
36
  end
37
37
 
38
+ # enqueue the job so that it can be
39
+ # performed
38
40
  def enqueue!
39
41
  Resque::Job.create(
40
42
  self.queue, self.class, *self.data_to_enqueue
@@ -1,3 +1,3 @@
1
1
  module ResqueExtensions
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -74,7 +74,7 @@ module ResqueExtensions
74
74
 
75
75
  end
76
76
 
77
- context "#enqueue" do
77
+ context "#enqueue!" do
78
78
 
79
79
  it "creates a new job for the class or instance" do
80
80
  async_method = AsyncMethod.new(MyClass, :my_class_method)
@@ -138,7 +138,6 @@ module ResqueExtensions
138
138
  })
139
139
 
140
140
  end
141
-
142
141
  end
143
142
 
144
143
  context "#queue" do
@@ -30,6 +30,22 @@ describe ResqueExtensions do
30
30
  job.perform
31
31
  end
32
32
 
33
+ it "calls the method if ResqueExtensions.async is
34
+ set to false" do
35
+ begin
36
+ ResqueExtensions.async = false
37
+
38
+ my_instance = MyClass.create(:name => "Dan")
39
+ my_instance.expects(:my_instance_method)
40
+
41
+ # async just calls send when ResqueExtensions.async is false
42
+ my_instance.async(:my_instance_method)
43
+
44
+ ensure
45
+ ResqueExtensions.async = true
46
+ end
47
+ end
48
+
33
49
  end
34
50
 
35
51
  context "#async" do
data/spec/spec_helper.rb CHANGED
@@ -8,9 +8,14 @@ require 'resque'
8
8
 
9
9
  Bundler.setup
10
10
 
11
+ db_path = File.expand_path(
12
+ File.dirname(__FILE__) + "/../tmp/test.sqlite"
13
+ )
14
+ puts db_path
15
+
11
16
  ActiveRecord::Base.establish_connection(
12
17
  :adapter => "sqlite3",
13
- :database => File.dirname(__FILE__) + "/../tmp/test.sqlite"
18
+ :database => db_path
14
19
  )
15
20
 
16
21
  Resque.redis = MockRedis.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-04 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: resque
@@ -48,6 +48,7 @@ files:
48
48
  - spec/lib/resque_extensions/async_method_spec.rb
49
49
  - spec/lib/resque_extensions_spec.rb
50
50
  - spec/spec_helper.rb
51
+ - tmp/.gitkeep
51
52
  homepage: https://github.com/dlangevin/resque_extensions
52
53
  licenses: []
53
54
  post_install_message: