loop_dance 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.document +5 -0
  2. data/Gemfile +18 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.rdoc +54 -0
  5. data/Rakefile +60 -0
  6. data/VERSION +1 -0
  7. data/init.rb +1 -0
  8. data/lib/loop_dance/commands.rb +91 -0
  9. data/lib/loop_dance/controller.rb +55 -0
  10. data/lib/loop_dance/dancer.rb +27 -0
  11. data/lib/loop_dance/railtie.rb +27 -0
  12. data/lib/loop_dance/task.rb +23 -0
  13. data/lib/loop_dance.rb +19 -0
  14. data/loop_dance.gemspec +142 -0
  15. data/rails/init.rb +1 -0
  16. data/spec/dancer_spec.rb +85 -0
  17. data/spec/spec_helper.rb +13 -0
  18. data/spec/task_spec.rb +42 -0
  19. data/test/rails/.gitignore +4 -0
  20. data/test/rails/Gemfile +35 -0
  21. data/test/rails/Rakefile +7 -0
  22. data/test/rails/app/controllers/application_controller.rb +3 -0
  23. data/test/rails/config/application.rb +42 -0
  24. data/test/rails/config/boot.rb +13 -0
  25. data/test/rails/config/database.yml +22 -0
  26. data/test/rails/config/environment.rb +5 -0
  27. data/test/rails/config/environments/development.rb +26 -0
  28. data/test/rails/config/environments/production.rb +49 -0
  29. data/test/rails/config/environments/test.rb +35 -0
  30. data/test/rails/config/initializers/backtrace_silencers.rb +7 -0
  31. data/test/rails/config/initializers/inflections.rb +10 -0
  32. data/test/rails/config/initializers/mime_types.rb +5 -0
  33. data/test/rails/config/initializers/secret_token.rb +7 -0
  34. data/test/rails/config/initializers/session_store.rb +8 -0
  35. data/test/rails/config/locales/en.yml +5 -0
  36. data/test/rails/config/routes.rb +58 -0
  37. data/test/rails/config.ru +4 -0
  38. data/test/rails/db/seeds.rb +7 -0
  39. data/test/rails/lib/dancers.rb +18 -0
  40. data/test/rails/lib/tasks/.gitkeep +0 -0
  41. data/test/rails/public/404.html +26 -0
  42. data/test/rails/public/422.html +26 -0
  43. data/test/rails/public/500.html +26 -0
  44. data/test/rails/public/favicon.ico +0 -0
  45. data/test/rails/public/images/rails.png +0 -0
  46. data/test/rails/public/index.html +239 -0
  47. data/test/rails/public/javascripts/application.js +2 -0
  48. data/test/rails/public/javascripts/controls.js +965 -0
  49. data/test/rails/public/javascripts/dragdrop.js +974 -0
  50. data/test/rails/public/javascripts/effects.js +1123 -0
  51. data/test/rails/public/javascripts/prototype.js +6001 -0
  52. data/test/rails/public/javascripts/rails.js +175 -0
  53. data/test/rails/public/robots.txt +5 -0
  54. data/test/rails/public/stylesheets/.gitkeep +0 -0
  55. data/test/rails/script/rails +6 -0
  56. metadata +285 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "activesupport", ">= 3.0"
5
+ gem "i18n"
6
+ gem "daemon_controller"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development, :test do
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ gem "ruby-debug"
15
+ gem "rspec"
16
+ gem "shoulda"
17
+ end
18
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Danil Pismenny
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = LoopDance
2
+
3
+ No forks. No threads. Just looped scheduler based on `daemon_controller` and `looper`
4
+
5
+ == Easy to install
6
+
7
+ gem 'loop_dance'
8
+
9
+ == Simple to setup
10
+
11
+ Just create file 'lib/loop_dance.rb':
12
+
13
+ class Dancer < LoopDance::Dancer
14
+
15
+ every 3.hours do
16
+ User.notify_all
17
+ end
18
+
19
+ every 60.seconds do
20
+ Report.checks
21
+ end
22
+
23
+ end
24
+
25
+ LoopDance automatically starts at the rails 3 server startup.
26
+
27
+ == Useful management
28
+
29
+ From the application:
30
+
31
+ Dancer.start unless Dancer.running?
32
+
33
+ By the rake tasks (TODO):
34
+
35
+ rake loop_dance:start
36
+ rake loop_dance:stop
37
+ rake loop_dance:status
38
+
39
+
40
+ == Contributing to loop_dance
41
+
42
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
43
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
44
+ * Fork the project
45
+ * Start a feature/bugfix branch
46
+ * Commit and push until you are happy with your contribution
47
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
48
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
49
+
50
+ == Copyright
51
+
52
+ Copyright (c) 2010 Danil Pismenny. See LICENSE.txt for
53
+ further details.
54
+
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "loop_dance"
16
+ gem.homepage = "http://github.com/dapi/loop_dance"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Simple auto-starting daemon based on the looper and daemon_controller}
19
+ gem.description = %Q{Really easy setup. Auto-start daaemon at rails server startup. Rake's tasks based control.} # ' anti ruby-mode
20
+ gem.email = "danil@orionet.ru"
21
+ gem.authors = ["Danil Pismenny"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'daemon_controller', '>= 0.2.5'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rspec/core'
37
+ require 'rspec/core/rake_task'
38
+ RSpec::Core::RakeTask.new(:spec) do |spec|
39
+ spec.pattern = FileList['spec/**/*_spec.rb']
40
+ end
41
+
42
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
43
+ spec.pattern = 'spec/**/*_spec.rb'
44
+ spec.rcov = true
45
+ end
46
+
47
+ task :default => :spec
48
+
49
+
50
+ #task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "loop_dance #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'loop_dance'
@@ -0,0 +1,91 @@
1
+ module LoopDance
2
+
3
+ module Commands
4
+
5
+ attr_accessor :tasks, :timeout, :maximal_timeout
6
+
7
+ def every( interval, &block )
8
+ @tasks = [] unless @tasks
9
+ @tasks << LoopDance::Task.new( interval, &block )
10
+ find_minimal_timeout interval
11
+ @maximal_timeout = interval if !@maximal_timeout || @maximal_timeout < interval
12
+ end
13
+
14
+ def dance
15
+ loop_init
16
+ if @tasks.empty?
17
+ log "No tasks defined."
18
+ else
19
+ while (@run) do
20
+ @tasks.each_with_index do |task, index|
21
+ if task.time_to_run?
22
+ log "Run task ##{index} for every #{task.interval.inspect}"
23
+ task.run
24
+ end
25
+ break unless @run
26
+ end
27
+ log "Sleep for #{@timeout.inspect}"
28
+ sleep @timeout.to_i if @run
29
+ end
30
+ end
31
+ log "shutting down"
32
+ end
33
+
34
+ def stop
35
+ @run = false
36
+ end
37
+
38
+ def pid_file
39
+ "log/#{name.underscore}.pid"
40
+ end
41
+
42
+ def log(text)
43
+ puts "#{Time.now} #{self}: #{text}"
44
+ end
45
+
46
+ private
47
+
48
+ def find_minimal_timeout( interval )
49
+ return @timeout = interval if @timeout.blank?
50
+ minimal = interval < @timeout ? interval : @timeout
51
+ while not timeout_devides? minimal
52
+ minimal-=1
53
+ end
54
+ @timeout = minimal
55
+ end
56
+
57
+ def timeout_devides?( timeout )
58
+ @tasks.each { |task|
59
+ m = (task.interval / timeout).to_i
60
+ return false unless m * timeout == task.interval
61
+ }
62
+ return true
63
+ end
64
+
65
+ def trap_signals
66
+ sigtrap = proc {
67
+ log "caught trapped signal, shutting down"
68
+ @run = false
69
+ }
70
+ ["SIGTERM", "SIGINT", "SIGHUP"].each do |signal|
71
+ trap signal, sigtrap
72
+ end
73
+ end
74
+
75
+ def loop_init
76
+ # we don't want to delay output to sdtout until the program stops, we want feedback!
77
+ $stdout.sync=true
78
+ write_pid
79
+ trap_signals
80
+ @run = true
81
+ log "Process started and sleep for #{timeout.inspect}. kill #{Process.pid} to stop"
82
+ end
83
+
84
+ def write_pid
85
+ file = File.new( pid_file, "w" )
86
+ file.print Process.pid.to_s
87
+ file.close
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,55 @@
1
+ require 'daemon_controller'
2
+
3
+ module LoopDance
4
+ class Controller < DaemonController
5
+
6
+ cattr_accessor :dancer, :start_timeout
7
+
8
+ self.start_timeout = 45
9
+
10
+ class << self
11
+
12
+ def new( dancer )
13
+ self.dancer = dancer
14
+ h = {
15
+ :identifier => dancer.name,
16
+ :daemonize_for_me => true,
17
+ :start_command => start_command,
18
+ :ping_command => lambda { true },
19
+ :pid_file => dancer.pid_file,
20
+ :log_file => log_file,
21
+ :start_timeout => start_timeout,
22
+ :log_file_activity_timeout => dancer.maximal_timeout + 3 # 3 seconds to stock
23
+ }
24
+ super h
25
+ end
26
+
27
+ def log_file
28
+ dancer.pid_file.gsub '.pid', '.log'
29
+ end
30
+
31
+ def start_command
32
+ if defined? Rails
33
+ "rails runner -e #{Rails.env} '#{dancer}.dance' 2>&1 >>#{log_file}"
34
+ else
35
+ "rails runner '#{dancer}.dance' 2>&1 >>#{log_file}"
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ def auto_start
42
+ dancer.log "Starting.. (#{@start_command})"
43
+ start unless running?
44
+ rescue => exception # DaemonController::StartTimeout
45
+ dancer.log "Exception until starting #{dancer}: #{exception.inspect}"
46
+ dancer.log exception.backtrace if defined?( Rails ) && !Rails.env.production?
47
+ end
48
+
49
+
50
+ #stop
51
+ #start
52
+ #running
53
+
54
+ end
55
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_support/core_ext'
2
+
3
+ module LoopDance
4
+
5
+ autoload :Commands, 'loop_dance/commands'
6
+ autoload :Controller, 'loop_dance/controller'
7
+
8
+ class Dancer
9
+
10
+
11
+ extend LoopDance::Commands
12
+
13
+
14
+ class << self
15
+
16
+ # Can start daemon automatically at rails server startup? true by default
17
+ cattr_accessor :start_automatic
18
+ self.start_automatic = true
19
+
20
+ def controller
21
+ @controller ||= LoopDance::Controller.new self
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails'
2
+ module LoopDance
3
+
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer 'loop_dance.initialize', :after => :after_initialize do
7
+
8
+ load_dancers
9
+ # Do not start dancers if rake or other tasks
10
+ LoopDance.auto_start if server_startup?
11
+ end
12
+
13
+ def load_dancers
14
+ require 'dancers'
15
+ end
16
+
17
+ # FIX: Is there more cute solution?
18
+ def server_startup?
19
+ caller.to_s=~/config\.ru/
20
+ end
21
+
22
+ rake_tasks do
23
+ #load "path/to/my_railtie.tasks"
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ class LoopDance::Task
2
+ attr_accessor :last_run_at, :block, :interval
3
+
4
+ def initialize( interval, &block )
5
+ run_count=0
6
+ self.interval = interval
7
+ self.block = block
8
+ self.last_run_at = Time.now
9
+ end
10
+
11
+ def time_to_run?
12
+ !last_run_at || last_run_at + interval <= Time.now
13
+ end
14
+
15
+ def run
16
+ block.call
17
+ rescue Exception => e
18
+ puts "Uncaught exception bubbled up: \n#{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")} "
19
+ ensure
20
+ self.last_run_at = Time.now
21
+ end
22
+
23
+ end
data/lib/loop_dance.rb ADDED
@@ -0,0 +1,19 @@
1
+ module LoopDance
2
+
3
+ autoload :Task, "loop_dance/task"
4
+ autoload :Dancer, "loop_dance/dancer"
5
+
6
+ def self.auto_start
7
+ return puts "LoopDance: No dancers to start" if LoopDance::Dancer.subclasses.empty?
8
+ LoopDance::Dancer.subclasses.each do |dancer|
9
+ dancer.controller.auto_start if dancer.start_automatic
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+ begin
16
+ require 'loop_dance/railtie'
17
+ rescue LoadError => e
18
+ puts "Can't load loop_dance/railtie"
19
+ end
@@ -0,0 +1,142 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{loop_dance}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Danil Pismenny"]
12
+ s.date = %q{2011-01-01}
13
+ s.description = %q{Really easy setup. Auto-start daaemon at rails server startup. Rake's tasks based control.}
14
+ s.email = %q{danil@orionet.ru}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "init.rb",
27
+ "lib/loop_dance.rb",
28
+ "lib/loop_dance/commands.rb",
29
+ "lib/loop_dance/controller.rb",
30
+ "lib/loop_dance/dancer.rb",
31
+ "lib/loop_dance/railtie.rb",
32
+ "lib/loop_dance/task.rb",
33
+ "loop_dance.gemspec",
34
+ "rails/init.rb",
35
+ "spec/dancer_spec.rb",
36
+ "spec/spec_helper.rb",
37
+ "spec/task_spec.rb",
38
+ "test/rails/.gitignore",
39
+ "test/rails/Gemfile",
40
+ "test/rails/Rakefile",
41
+ "test/rails/app/controllers/application_controller.rb",
42
+ "test/rails/config.ru",
43
+ "test/rails/config/application.rb",
44
+ "test/rails/config/boot.rb",
45
+ "test/rails/config/database.yml",
46
+ "test/rails/config/environment.rb",
47
+ "test/rails/config/environments/development.rb",
48
+ "test/rails/config/environments/production.rb",
49
+ "test/rails/config/environments/test.rb",
50
+ "test/rails/config/initializers/backtrace_silencers.rb",
51
+ "test/rails/config/initializers/inflections.rb",
52
+ "test/rails/config/initializers/mime_types.rb",
53
+ "test/rails/config/initializers/secret_token.rb",
54
+ "test/rails/config/initializers/session_store.rb",
55
+ "test/rails/config/locales/en.yml",
56
+ "test/rails/config/routes.rb",
57
+ "test/rails/db/seeds.rb",
58
+ "test/rails/lib/dancers.rb",
59
+ "test/rails/lib/tasks/.gitkeep",
60
+ "test/rails/public/404.html",
61
+ "test/rails/public/422.html",
62
+ "test/rails/public/500.html",
63
+ "test/rails/public/favicon.ico",
64
+ "test/rails/public/images/rails.png",
65
+ "test/rails/public/index.html",
66
+ "test/rails/public/javascripts/application.js",
67
+ "test/rails/public/javascripts/controls.js",
68
+ "test/rails/public/javascripts/dragdrop.js",
69
+ "test/rails/public/javascripts/effects.js",
70
+ "test/rails/public/javascripts/prototype.js",
71
+ "test/rails/public/javascripts/rails.js",
72
+ "test/rails/public/robots.txt",
73
+ "test/rails/public/stylesheets/.gitkeep",
74
+ "test/rails/script/rails"
75
+ ]
76
+ s.homepage = %q{http://github.com/dapi/loop_dance}
77
+ s.licenses = ["MIT"]
78
+ s.require_paths = ["lib"]
79
+ s.rubygems_version = %q{1.3.7}
80
+ s.summary = %q{Simple auto-starting daemon based on the looper and daemon_controller}
81
+ s.test_files = [
82
+ "spec/dancer_spec.rb",
83
+ "spec/spec_helper.rb",
84
+ "spec/task_spec.rb",
85
+ "test/rails/app/controllers/application_controller.rb",
86
+ "test/rails/config/application.rb",
87
+ "test/rails/config/boot.rb",
88
+ "test/rails/config/environment.rb",
89
+ "test/rails/config/environments/development.rb",
90
+ "test/rails/config/environments/production.rb",
91
+ "test/rails/config/environments/test.rb",
92
+ "test/rails/config/initializers/backtrace_silencers.rb",
93
+ "test/rails/config/initializers/inflections.rb",
94
+ "test/rails/config/initializers/mime_types.rb",
95
+ "test/rails/config/initializers/secret_token.rb",
96
+ "test/rails/config/initializers/session_store.rb",
97
+ "test/rails/config/routes.rb",
98
+ "test/rails/db/seeds.rb",
99
+ "test/rails/lib/dancers.rb"
100
+ ]
101
+
102
+ if s.respond_to? :specification_version then
103
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
104
+ s.specification_version = 3
105
+
106
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
107
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
108
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
109
+ s.add_runtime_dependency(%q<daemon_controller>, [">= 0"])
110
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
111
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
112
+ s.add_development_dependency(%q<rcov>, [">= 0"])
113
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
114
+ s.add_development_dependency(%q<rspec>, [">= 0"])
115
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
116
+ s.add_runtime_dependency(%q<daemon_controller>, [">= 0.2.5"])
117
+ else
118
+ s.add_dependency(%q<activesupport>, [">= 3.0"])
119
+ s.add_dependency(%q<i18n>, [">= 0"])
120
+ s.add_dependency(%q<daemon_controller>, [">= 0"])
121
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
122
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
123
+ s.add_dependency(%q<rcov>, [">= 0"])
124
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
125
+ s.add_dependency(%q<rspec>, [">= 0"])
126
+ s.add_dependency(%q<shoulda>, [">= 0"])
127
+ s.add_dependency(%q<daemon_controller>, [">= 0.2.5"])
128
+ end
129
+ else
130
+ s.add_dependency(%q<activesupport>, [">= 3.0"])
131
+ s.add_dependency(%q<i18n>, [">= 0"])
132
+ s.add_dependency(%q<daemon_controller>, [">= 0"])
133
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
134
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
135
+ s.add_dependency(%q<rcov>, [">= 0"])
136
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
137
+ s.add_dependency(%q<rspec>, [">= 0"])
138
+ s.add_dependency(%q<shoulda>, [">= 0"])
139
+ s.add_dependency(%q<daemon_controller>, [">= 0.2.5"])
140
+ end
141
+ end
142
+
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ Kernel.load File.join(File.dirname(__FILE__), '..', 'init.rb')
@@ -0,0 +1,85 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe LoopDance do
4
+
5
+ describe "setup" do
6
+ end
7
+
8
+ describe "finds minimal interval"
9
+
10
+ describe "examples" do
11
+
12
+ before(:all) do
13
+ class Dancer1 < LoopDance::Dancer
14
+ every 2.seconds do
15
+ end
16
+ every 4.seconds do
17
+ end
18
+ every 6.seconds do
19
+ end
20
+ every 10.seconds do
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ it { Dancer1.tasks.count.should == 4 }
27
+ it { Dancer1.timeout.should == 2 }
28
+ it { LoopDance::Dancer.tasks.should be_blank }
29
+ it { Dancer1.maximal_timeout.should == 10 }
30
+
31
+
32
+ describe "another dancer not change first dancer's tasks" do
33
+
34
+ before(:all) do
35
+ class Dancer2 < LoopDance::Dancer
36
+ every 6.seconds do
37
+ end
38
+ every 11.seconds do
39
+ end
40
+ end
41
+ end
42
+
43
+ it { Dancer2.tasks.count.should == 2 }
44
+ it { Dancer2.timeout.should == 1 }
45
+ it { Dancer2.maximal_timeout.should == 11 }
46
+
47
+ end
48
+
49
+ describe "find right minimal timeout" do
50
+
51
+ before(:all) do
52
+ class Dancer3 < LoopDance::Dancer
53
+ every 6.seconds do
54
+ end
55
+ every 9.seconds do
56
+ end
57
+ end
58
+ end
59
+
60
+ it { Dancer3.tasks.count.should == 2 }
61
+ it { Dancer3.timeout.should == 3 }
62
+ it { Dancer3.maximal_timeout.should == 9 }
63
+
64
+ end
65
+
66
+ describe "method stop stops the loop" do
67
+
68
+ before(:all) do
69
+ class Dancer < LoopDance::Dancer
70
+ every 2.seconds do
71
+ stop
72
+ end
73
+ end
74
+ end
75
+
76
+ it { Dancer.dance }
77
+ it { Dancer.maximal_timeout.should == 2 }
78
+
79
+ end
80
+
81
+
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'loop_dance'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end