ActionTimer 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  = CHANGELOG
2
2
 
3
+ == 0.1.0
4
+ * remove excess exceptions
5
+ * use logger directly
6
+ * add a splat for data passage
7
+
3
8
  == 0.0.2
4
9
  * added new Timer::running? method
5
10
  * added new Timer::pause method
data/README.rdoc CHANGED
@@ -2,20 +2,16 @@
2
2
 
3
3
  ActionTimer is a helper for timed events. It allows for single and recurring actions to be executed in an efficient manner. It makes use of a single thread to keep time on registered actions and uses an ActionPool to execute actions. Simple and effective.
4
4
 
5
- ==== useful links
6
- * {trac site}[http://dev.modspox.com/trac/actiontimer]
7
- * {RDocs}[http://dev.modspox.com/~sine/ActionTimer]
8
-
9
5
  === install (easy):
10
6
 
11
- gem install --include-dependencies ActionTimer
7
+ gem install ActionTimer
12
8
 
13
9
  === install (less easy):
14
10
 
15
11
  git clone http://github.com/spox/actiontimer.git
16
12
  cd actiontimer
17
13
  gem build actiontimer.gemspec
18
- gem install ActionTimer-x.x.x.gem
14
+ gem install ./
19
15
 
20
16
  === Simple example of using the timer:
21
17
 
data/actiontimer.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'ActionTimer'
3
- s.author = %q(spox)
4
- s.email = %q(spox@modspox.com)
5
- s.version = '0.0.2'
6
- s.summary = %q(Simple timer for a complex world)
3
+ s.author = 'spox'
4
+ s.email = 'spox@modspox.com'
5
+ s.version = '0.1.0'
6
+ s.summary = 'Simple timer for a complex world'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.has_rdoc = true
9
9
  s.rdoc_options = %w(--title ActionTimer --main README.rdoc --line-numbers --inline-source)
@@ -12,14 +12,6 @@ spec = Gem::Specification.new do |s|
12
12
  s.require_paths = %w(lib)
13
13
  s.add_dependency 'ActionPool'
14
14
  s.required_ruby_version = '>= 1.8.6'
15
- s.homepage = %q(http://dev.modspox.com/trac/ActionTimer)
16
- description = []
17
- File.open("README.rdoc") do |file|
18
- file.each do |line|
19
- line.chomp!
20
- break if line.empty?
21
- description << "#{line.gsub(/\[\d\]/, '')}"
22
- end
23
- end
24
- s.description = description[1..-1].join(" ")
15
+ s.homepage = 'http://github.com/spox/actiontimer'
16
+ s.description = 'ActionTimer is a simple timer for recurring actions. It supports single and recurring actions with an easy to use API.'
25
17
  end
@@ -67,7 +67,7 @@ module ActionTimer
67
67
 
68
68
  # Run the action
69
69
  def run
70
- @data.nil? ? @block.call : @block.call(@data)
70
+ @data.nil? ? @block.call : @block.call(*@data)
71
71
  end
72
72
  end
73
73
  end
@@ -5,17 +5,4 @@ module ActionTimer
5
5
 
6
6
  class NotRunning < Exception
7
7
  end
8
-
9
- class InvalidType < Exception
10
- attr_reader :given
11
- attr_reader :expected
12
- def initialize(g,e)
13
- @given = given
14
- @expected = e
15
- end
16
-
17
- def to_s
18
- "Given type: #{g} Expected type: #{e}"
19
- end
20
- end
21
8
  end
@@ -1,5 +1,5 @@
1
1
  require 'actionpool'
2
- ['Action', 'Exceptions', 'LogHelper'].each{|f| require "actiontimer/#{f}"}
2
+ ['Action', 'Exceptions'].each{|f| require "actiontimer/#{f}"}
3
3
 
4
4
  module ActionTimer
5
5
  class Timer
@@ -10,11 +10,11 @@ module ActionTimer
10
10
  auto_start = true
11
11
  if(args.is_a?(Hash))
12
12
  @pool = args[:pool] ? args[:pool] : ActionPool::Pool.new
13
- @logger = LogHelper.new(args[:logger])
13
+ @logger = args[:logger] && args[:logger].is_a?(Logger) ? args[:logger] : Logger.new(nil)
14
14
  auto_start = args.has_key?(:auto_start) ? args[:auto_start] : true
15
15
  else
16
16
  @pool = args.is_a?(ActionPool::Pool) ? args : ActionPool::Pool.new
17
- @logger = LogHelper.new(extra)
17
+ @logger = extra && extra.is_a?(Logger) ? extra : Logger.new(nil)
18
18
  end
19
19
  @actions = []
20
20
  @new_actions = []
@@ -50,9 +50,9 @@ module ActionTimer
50
50
  # actions:: Array of actions
51
51
  # Add multiple Actions to the timer at once
52
52
  def mass_add(actions)
53
- raise InvalidType.new(Array, actions.class) unless actions.is_a?(Array)
53
+ raise ArgumentError.new('Expecting an array') unless actions.is_a?(Array)
54
54
  actions.each do |action|
55
- raise InvalidType.new(ActionTimer::Action, action.class) unless action.is_a?(Action)
55
+ raise ArgumentError.new('Expecting an Action') unless action.is_a?(Action)
56
56
  end
57
57
  @add_lock.synchronize{ @new_actions = @new_actions + actions }
58
58
  wakeup if running?
@@ -61,7 +61,7 @@ module ActionTimer
61
61
  # action:: Action to remove from timer
62
62
  # Remove given action from timer
63
63
  def remove(action)
64
- raise InvalidType.new(ActionTimer::Action, action.class) unless action.is_a?(Action)
64
+ raise ArgumentError.new('Expecting an action') unless action.is_a?(Action)
65
65
  @actions.delete(action)
66
66
  wakeup if running?
67
67
  end
@@ -159,7 +159,7 @@ module ActionTimer
159
159
  @pool.process do
160
160
  begin
161
161
  action.run
162
- rescue Object => boom
162
+ rescue StandardError => boom
163
163
  @logger.error("Timer caught an error while running action: #{boom}\n#{boom.backtrace.join("\n")}")
164
164
  end
165
165
  end
data/tests/run_tests.rb CHANGED
@@ -55,6 +55,11 @@ class TimerTests < Test::Unit::TestCase
55
55
  @timer.add(1, true, 3){|a| result = a}
56
56
  sleep(2)
57
57
  assert_equal(3, result)
58
+ @timer.add(1, true, [3,4,['foobar']]){|a,b,c| result = [b,a,c]}
59
+ sleep(2)
60
+ assert_equal(4, result[0])
61
+ assert_equal(3, result[1])
62
+ assert(result[2].is_a?(Array))
58
63
  end
59
64
 
60
65
  # Check that the timer's auto starting mechanism
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ActionTimer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - spox
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-20 00:00:00 -07:00
12
+ date: 2009-12-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: ""
25
+ description: ActionTimer is a simple timer for recurring actions. It supports single and recurring actions with an easy to use API.
26
26
  email: spox@modspox.com
27
27
  executables: []
28
28
 
@@ -33,21 +33,19 @@ extra_rdoc_files:
33
33
  - LICENSE
34
34
  - CHANGELOG
35
35
  files:
36
- - tests
37
- - tests/run_tests.rb
38
36
  - actiontimer.gemspec
39
- - README.rdoc
40
- - lib
41
- - lib/actiontimer
37
+ - tests/run_tests.rb
38
+ - lib/actiontimer.rb
39
+ - lib/actiontimer/Timer.rb
42
40
  - lib/actiontimer/Action.rb
43
- - lib/actiontimer/LogHelper.rb
44
41
  - lib/actiontimer/Exceptions.rb
45
- - lib/actiontimer/Timer.rb
46
- - lib/actiontimer.rb
47
- - LICENSE
48
42
  - CHANGELOG
43
+ - LICENSE
44
+ - README.rdoc
49
45
  has_rdoc: true
50
- homepage: http://dev.modspox.com/trac/ActionTimer
46
+ homepage: http://github.com/spox/actiontimer
47
+ licenses: []
48
+
51
49
  post_install_message:
52
50
  rdoc_options:
53
51
  - --title
@@ -73,9 +71,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
71
  requirements: []
74
72
 
75
73
  rubyforge_project:
76
- rubygems_version: 1.3.1
74
+ rubygems_version: 1.3.5
77
75
  signing_key:
78
- specification_version: 2
76
+ specification_version: 3
79
77
  summary: Simple timer for a complex world
80
78
  test_files: []
81
79
 
@@ -1,28 +0,0 @@
1
- require 'logger'
2
-
3
- module ActionTimer
4
-
5
- class LogHelper
6
-
7
- def initialize(logger=nil)
8
- @logger = logger
9
- end
10
-
11
- def info(m)
12
- @logger.info(m) unless @logger.nil?
13
- end
14
-
15
- def warn(m)
16
- @logger.warn(m) unless @logger.nil?
17
- end
18
-
19
- def fatal(m)
20
- @logger.fatal(m) unless @logger.nil?
21
- end
22
-
23
- def error(m)
24
- @logger.error(m) unless @logger.nil?
25
- end
26
- end
27
-
28
- end