Class: Pub
- Inherits:
-
Object
- Object
- Pub
- Defined in:
- lib/pub.rb,
lib/pub/patron.rb,
lib/pub/helpers.rb,
lib/pub/version.rb,
lib/pub/bartender.rb
Overview
A Redis-backed pub with a non-blocking bar counter.
Or, putting aside the metaphor for a moment:
A processing queue where consumers, instead of simply queuing jobs and getting on with their lives, queue and wait for a response without blocking the Ruby process.
Each pub instance is a distinct queue.
Defined Under Namespace
Modules: Helpers Classes: Bartender, Patron
Constant Summary collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
-
.beer_tap ⇒ Object
A device that dispenses beer.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the pub.
Class Method Summary collapse
-
.counter ⇒ Object
The bar counter.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the pub for the night.
-
#initialize(name) ⇒ Pub
constructor
Enters a pub.
-
#new_bartender ⇒ Object
A new bartender.
-
#new_patron(timeout = 5) ⇒ Object
A new patron.
Constructor Details
#initialize(name) ⇒ Pub
Enters a pub.
Takes the name of the pub and an optional block.
Pub.new('Ye Olde Rubies') do |pub|
patron = pub.new_patron
patron.order('Guinness') do |beer|
JSON.parse(beer).drink
end
end
45 46 47 48 |
# File 'lib/pub.rb', line 45 def initialize(name) @name = name EM.synchrony { yield self } if block_given? end |
Class Attribute Details
.beer_tap ⇒ Object
A device that dispenses beer.
23 24 25 |
# File 'lib/pub.rb', line 23 def beer_tap @beer_tap end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the pub.
19 20 21 |
# File 'lib/pub.rb', line 19 def name @name end |
Class Method Details
.counter ⇒ Object
The bar counter.
26 27 28 |
# File 'lib/pub.rb', line 26 def counter Redis.new(url: beer_tap) end |