acts_as_queue 0.1.2 → 0.1.3
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.
- data/README.rdoc +31 -0
- data/acts_as_queue.gemspec +1 -1
- data/lib/acts_as_queue.rb +22 -0
- metadata +5 -12
- data/README +0 -27
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= acts_as_queue
|
2
|
+
|
3
|
+
<tt>acts_as_queue</tt> is a gem for ActiveRecord that allows you to turn any of your ActiveRecord models into a queue.
|
4
|
+
|
5
|
+
acts_as_queue provides you with methods to simplify using your ActiveRecord as a queue. The two key methods it provides are <tt>Push</tt> and <tt>Pop</tt>.
|
6
|
+
|
7
|
+
<tt>Push</tt> is used when you want to add an item to your queue. <tt>Pop</tt> is used when you need to process or remove the earliest item from your queue.
|
8
|
+
|
9
|
+
== Using the default unbounded queue
|
10
|
+
|
11
|
+
class Post < ActiveRecord::Base
|
12
|
+
acts_as_queue
|
13
|
+
end
|
14
|
+
|
15
|
+
# Pushing new posts onto the queue.
|
16
|
+
Post.push :name => "Hello World"
|
17
|
+
Post.push :name => "Using Rails"
|
18
|
+
|
19
|
+
# Popping the item at the front of the queue.
|
20
|
+
Post.pop
|
21
|
+
|
22
|
+
== Using a bounded queue
|
23
|
+
|
24
|
+
class Message < ActiveRecord::Base
|
25
|
+
acts_as_queue :size => 10
|
26
|
+
end
|
27
|
+
|
28
|
+
# Pushing 20 new messages onto the queue.
|
29
|
+
(1..20).each { |i| Message.push :description => "Message #{i}" }
|
30
|
+
|
31
|
+
Message.count # Just 10 messages on the queue
|
data/acts_as_queue.gemspec
CHANGED
data/lib/acts_as_queue.rb
CHANGED
@@ -4,8 +4,27 @@ module ActsAsQueue
|
|
4
4
|
base.extend(ClassMethods)
|
5
5
|
end
|
6
6
|
|
7
|
+
# +acts_as_queue+ allows you to turn any ActiveRecord model into a queue, providing you with the necessary actions to manipulate your model.
|
8
|
+
# The class also allows you to define a queue size so that your queue can then become a bounded queue.
|
9
|
+
#
|
10
|
+
# acts_as_queue example
|
11
|
+
#
|
12
|
+
# class Post < ActiveRecord::Base
|
13
|
+
# acts_as_queue
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # Pushing new posts onto the queue.
|
17
|
+
# Post.push :name => "Hello World"
|
18
|
+
# Post.push :name => "Using Rails"
|
19
|
+
#
|
20
|
+
# # Popping the item at the front of the queue.
|
21
|
+
# Post.pop
|
7
22
|
module ClassMethods
|
8
23
|
|
24
|
+
# Configuration options are:
|
25
|
+
#
|
26
|
+
# +size+ - specifies the bounded queue size.
|
27
|
+
# Example: +acts_as_queue :size => 20+
|
9
28
|
def acts_as_queue(options = {})
|
10
29
|
configuration = { :size => "0" }
|
11
30
|
configuration.update(options) if options.is_a?(Hash)
|
@@ -18,6 +37,7 @@ module ActsAsQueue
|
|
18
37
|
EOV
|
19
38
|
end
|
20
39
|
|
40
|
+
# Pushes an item onto the queue.
|
21
41
|
def push(attributes)
|
22
42
|
if (self.queue_size > 0) && (self.count == self.queue_size)
|
23
43
|
popped = self.pop
|
@@ -26,12 +46,14 @@ module ActsAsQueue
|
|
26
46
|
self.create(attributes)
|
27
47
|
end
|
28
48
|
|
49
|
+
# Pops the earliest item from the queue.
|
29
50
|
def pop
|
30
51
|
attributes = self.first.attributes
|
31
52
|
self.first.delete
|
32
53
|
attributes.inject({}) { |attribute,(k,v)| attribute[k.to_sym] = v; attribute }
|
33
54
|
end
|
34
55
|
|
56
|
+
# Returns the number of items in the queue.
|
35
57
|
def count
|
36
58
|
self.find(:all).count
|
37
59
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 31
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Matthew Lang
|
@@ -15,18 +14,16 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-06 00:00:00 +00:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: shoulda
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 37
|
30
27
|
segments:
|
31
28
|
- 2
|
32
29
|
- 11
|
@@ -47,7 +44,7 @@ files:
|
|
47
44
|
- .gitignore
|
48
45
|
- Gemfile
|
49
46
|
- MIT-LICENSE
|
50
|
-
- README
|
47
|
+
- README.rdoc
|
51
48
|
- Rakefile
|
52
49
|
- acts_as_queue.gemspec
|
53
50
|
- init.rb
|
@@ -63,27 +60,23 @@ rdoc_options: []
|
|
63
60
|
require_paths:
|
64
61
|
- lib
|
65
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
63
|
requirements:
|
68
64
|
- - ">="
|
69
65
|
- !ruby/object:Gem::Version
|
70
|
-
hash: 3
|
71
66
|
segments:
|
72
67
|
- 0
|
73
68
|
version: "0"
|
74
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
70
|
requirements:
|
77
71
|
- - ">="
|
78
72
|
- !ruby/object:Gem::Version
|
79
|
-
hash: 3
|
80
73
|
segments:
|
81
74
|
- 0
|
82
75
|
version: "0"
|
83
76
|
requirements: []
|
84
77
|
|
85
78
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.3.
|
79
|
+
rubygems_version: 1.3.6
|
87
80
|
signing_key:
|
88
81
|
specification_version: 3
|
89
82
|
summary: Allows you to turn your ActiveRecord models into queues.
|
data/README
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
= acts_as_queue
|
2
|
-
|
3
|
-
acts_as_queue is a plugin for ActiveRecord that allows you to turn any of your ActiveRecord models into a queue.
|
4
|
-
|
5
|
-
== Using the default queue size
|
6
|
-
|
7
|
-
class Post < ActiveRecord::Base
|
8
|
-
acts_as_queue
|
9
|
-
end
|
10
|
-
|
11
|
-
# Pushing new posts onto the queue.
|
12
|
-
Post.push :name => "Hello World"
|
13
|
-
Post.push :name => "Using Rails"
|
14
|
-
|
15
|
-
# Popping the item at the front of the queue.
|
16
|
-
Post.pop
|
17
|
-
|
18
|
-
== Using a queue size
|
19
|
-
|
20
|
-
class Message < ActiveRecord::Base
|
21
|
-
acts_as_queue :size => 10
|
22
|
-
end
|
23
|
-
|
24
|
-
# Pushing 20 new messages onto the queue.
|
25
|
-
(1..20).each { |i| Message.push :description => "Message #{i}" }
|
26
|
-
|
27
|
-
Message.count # Just 10 messages on the queue
|