entp-astrotrain 0.3.0 → 0.3.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/astrotrain.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{astrotrain}
5
- s.version = "0.3.0"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["technoweenie"]
@@ -3,8 +3,8 @@ module Astrotrain
3
3
  class Worker
4
4
  attr_accessor :logger, :sleep_duration, :name
5
5
 
6
- def self.start(options = {})
7
- new(options).run
6
+ def self.start(options = {}, &block)
7
+ new(options).run(&block)
8
8
  end
9
9
 
10
10
  def initialize(options = {})
@@ -14,17 +14,21 @@ module Astrotrain
14
14
  @logger = options.key?(:logger) ? options[:logger] : STDOUT
15
15
  end
16
16
 
17
- def run
18
- setup do
19
- files = 0
20
- Dir.foreach(Message.queue_path) do |f|
21
- next if f =~ /^\.{1,2}$/
22
- files += 1
23
- file = File.join(Message.queue_path, f)
24
- Message.receive_file(file)
25
- end
26
- files
17
+ # override this to perform other tasks in the astrotrain job loop
18
+ def run(&block)
19
+ block ||= lambda { |w| w.process_emails }
20
+ setup(&block)
21
+ end
22
+
23
+ def process_emails
24
+ files = 0
25
+ Dir.foreach(Message.queue_path) do |f|
26
+ next if f =~ /^\.{1,2}$/
27
+ files += 1
28
+ file = File.join(Message.queue_path, f)
29
+ Message.receive_file(file)
27
30
  end
31
+ files
28
32
  end
29
33
 
30
34
  def say(s)
@@ -42,7 +46,7 @@ module Astrotrain
42
46
 
43
47
  loop do
44
48
  count = nil
45
- realtime = Benchmark.realtime { count = yield }
49
+ realtime = Benchmark.realtime { count = yield(self) }
46
50
 
47
51
  break if $exit
48
52
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entp-astrotrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - technoweenie