Class: Batchr
- Inherits:
-
Object
- Object
- Batchr
- Defined in:
- lib/batchr.rb,
lib/batchr/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#message ⇒ Object
Returns the value of attribute message.
-
#receiver ⇒ Object
Returns the value of attribute receiver.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #empty_bucket ⇒ Object
-
#initialize(opts = {}) ⇒ Batchr
constructor
A new instance of Batchr.
- #run_batch ⇒ Object (also: #finish)
- #run_if_necessary ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Batchr
Returns a new instance of Batchr.
14 15 16 17 |
# File 'lib/batchr.rb', line 14 def initialize opts = {} @batch_size = opts[:batch_size] ? opts[:batch_size] : 400 @bucket = [] end |
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
3 4 5 |
# File 'lib/batchr.rb', line 3 def batch_size @batch_size end |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/batchr.rb', line 3 def bucket @bucket end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'lib/batchr.rb', line 4 def end |
#receiver ⇒ Object
Returns the value of attribute receiver.
4 5 6 |
# File 'lib/batchr.rb', line 4 def receiver @receiver end |
Class Method Details
.batch(receiver, message) {|batchr| ... } ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/batchr.rb', line 6 def self.batch receiver, batchr = new batchr.receiver = receiver batchr. = yield batchr batchr.finish end |
Instance Method Details
#<<(value) ⇒ Object
24 25 26 27 |
# File 'lib/batchr.rb', line 24 def << value @bucket << value run_if_necessary end |
#empty_bucket ⇒ Object
33 34 35 |
# File 'lib/batchr.rb', line 33 def empty_bucket @bucket = [] end |
#run_batch ⇒ Object Also known as: finish
37 38 39 40 41 42 |
# File 'lib/batchr.rb', line 37 def run_batch unless bucket.empty? receiver.send(, bucket) empty_bucket end end |
#run_if_necessary ⇒ Object
29 30 31 |
# File 'lib/batchr.rb', line 29 def run_if_necessary run_batch if @bucket.size >= @batch_size end |