sucker_punch 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sucker_punch.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'celluloid'
2
2
  require 'sucker_punch/exceptions'
3
+ require 'sucker_punch/queue'
4
+ require 'sucker_punch/worker'
5
+ require 'sucker_punch/version'
3
6
 
4
7
  module SuckerPunch
5
8
  extend self
@@ -9,21 +12,14 @@ module SuckerPunch
9
12
  end
10
13
 
11
14
  def queue(options = {})
12
- raise SuckerPunch::MissingQueueName unless options[:name]
13
- raise SuckerPunch::MissingWorkerName unless options[:worker]
15
+ raise MissingQueueName unless options[:name]
16
+ raise MissingWorkerName unless options[:worker]
14
17
 
15
18
  klass = options.fetch(:worker)
16
19
  registry_name = options.fetch(:name)
17
20
  size = options.fetch(:size, nil)
18
21
 
19
- Celluloid::Actor[registry_name] = if size
20
- klass.send(:pool, size: size)
21
- else
22
- klass.send(:pool)
23
- end
22
+ q = Queue.new(registry_name)
23
+ q.register(klass, size)
24
24
  end
25
- end
26
-
27
- require 'sucker_punch/queue'
28
- require 'sucker_punch/worker'
29
- require 'sucker_punch/version'
25
+ end
@@ -1,9 +1,21 @@
1
1
  module SuckerPunch
2
- module Queue
3
- extend self
2
+ class Queue
3
+ attr_reader :name
4
4
 
5
- def [](name)
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def self.[](name)
6
10
  Celluloid::Actor[name]
7
11
  end
12
+
13
+ def register(klass, size)
14
+ Celluloid::Actor[name] = if size
15
+ klass.send(:pool, size: size)
16
+ else
17
+ klass.send(:pool)
18
+ end
19
+ end
8
20
  end
9
21
  end
@@ -1,3 +1,3 @@
1
1
  module SuckerPunch
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
data/spec/queue_spec.rb CHANGED
@@ -3,6 +3,9 @@ require 'spec_helper'
3
3
  class FakeWorker
4
4
  include Celluloid
5
5
  end
6
+ class FakeOtherWorker
7
+ include Celluloid
8
+ end
6
9
 
7
10
  describe SuckerPunch::Queue do
8
11
  describe ".[]" do
@@ -12,4 +15,19 @@ describe SuckerPunch::Queue do
12
15
  SuckerPunch::Queue[:fake]
13
16
  end
14
17
  end
18
+
19
+ describe "#register" do
20
+ before(:each) do
21
+ SuckerPunch::Queue.new(:crazy_queue).register(FakeWorker, 7)
22
+ end
23
+
24
+ it "turns the class into an actor" do
25
+ Celluloid::Actor[:crazy_queue].should be_a(FakeWorker)
26
+ Celluloid::Actor[:crazy_queue].methods.should include(:async)
27
+ end
28
+
29
+ it "sets worker size" do
30
+ Celluloid::Actor[:crazy_queue].size.should == 7
31
+ end
32
+ end
15
33
  end
@@ -6,24 +6,15 @@ end
6
6
 
7
7
  describe SuckerPunch do
8
8
  context "config" do
9
+
9
10
  context "properly configured" do
10
- before(:all) do
11
+ it "registers the queue" do
12
+ SuckerPunch::Queue.any_instance.should_receive(:register).with(FakeWorker, 7)
13
+
11
14
  SuckerPunch.config do
12
15
  queue name: :crazy_queue, worker: FakeWorker, size: 7
13
16
  end
14
17
  end
15
-
16
- it "turns the class into an actor" do
17
- Celluloid::Actor[:crazy_queue].should be_a(FakeWorker)
18
- Celluloid::Actor[:crazy_queue].methods.should include(:async)
19
- end
20
-
21
- it "allow asynchrounous processing" do
22
- end
23
-
24
- it "sets worker size" do
25
- Celluloid::Actor[:crazy_queue].size.should == 7
26
- end
27
18
  end
28
19
 
29
20
  context "with no queue name" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: