daemons-rails 1.1.0.alpha → 1.1.0

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.
@@ -3,6 +3,10 @@ Daemons Rails support (based on http://github.com/dougal/daemon_generator)
3
3
 
4
4
  To get it work just add dependency to this gem in your Gemfile.
5
5
 
6
+ ## NOTES ##
7
+
8
+ If you switching from version before 1.1 you may need to move script/daemons file to lib/daemons directory.
9
+
6
10
  ## GENERATOR ##
7
11
 
8
12
  rails generate daemon <name>
@@ -61,6 +65,6 @@ Notice: this feature available only from version 1.1 and old generated daemons c
61
65
 
62
66
  ## CHANGES ##
63
67
 
64
- * 1.1.0 - supported custom directory for daemons
68
+ * 1.1.0 - supported custom directory for daemons, support multiple daemons directories
65
69
  * 1.0.0 - changed api for Daemons::Rails::Monitoring, fixed path in template for script, improved documentation, added RSpec
66
70
  * 0.0.3 - added rake for running script without daemonization (rake daemon:\<name\>)
@@ -1,6 +1,8 @@
1
1
  require 'yaml'
2
2
  require 'erb'
3
3
 
4
+ require 'daemons/rails'
5
+
4
6
  module Daemons
5
7
  module Rails
6
8
  class Config
@@ -14,6 +16,10 @@ module Daemons
14
16
  @options[:script] ||= File.join(root_path, daemons_dir, "#{app_name}.rb")
15
17
  end
16
18
 
19
+ def self.for_controller(controller_path, root = Daemons::Rails.configuration.root)
20
+ new(File.basename(controller_path, '_ctl'), root, Pathname.new(controller_path).parent.relative_path_from(root))
21
+ end
22
+
17
23
  def [](key)
18
24
  @options[key]
19
25
  end
@@ -2,35 +2,56 @@ require "daemons"
2
2
  require "daemons/rails"
3
3
  require "daemons/rails/config"
4
4
  require "daemons/rails/controller"
5
+ require "active_support/core_ext/module/delegation.rb"
5
6
 
6
7
  module Daemons
7
8
  module Rails
8
9
  class Monitoring
10
+ def self.default
11
+ @default ||= self.new
12
+ end
13
+
14
+ def initialize(daemons_path = Daemons::Rails.configuration.daemons_path)
15
+ @daemons_path = daemons_path
16
+ end
17
+
18
+ singleton_class.delegate :daemons_path=, :daemons_path, :controller, :controllers, :statuses, :start, :stop, :to => :default
19
+
20
+ # @deprecate use Daemons::Rails::Monitoring#daemons_path=
9
21
  def self.daemons_directory=(value)
10
- @daemons_directory = value
22
+ self.daemons_path = value
11
23
  end
12
24
 
25
+ # @deprecate use Daemons::Rails::Monitoring#daemons_path
13
26
  def self.daemons_directory
14
- @daemons_directory || Daemons::Rails.configuration.daemons_path
27
+ self.daemons_path
28
+ end
29
+
30
+ def daemons_path=(value)
31
+ @daemons_path = value
32
+ end
33
+
34
+ def daemons_path
35
+ @daemons_path || Daemons::Rails.configuration.daemons_path
15
36
  end
16
37
 
17
- def self.controller(app_name)
38
+ def controller(app_name)
18
39
  controllers.find { |controller| controller.app_name == app_name }
19
40
  end
20
41
 
21
- def self.controllers
22
- Pathname.glob(daemons_directory.join('*_ctl')).map { |path| Daemons::Rails::Controller.new(path) }
42
+ def controllers
43
+ Pathname.glob(daemons_path.join('*_ctl')).map { |path| Daemons::Rails::Controller.new(path) }
23
44
  end
24
45
 
25
- def self.statuses
46
+ def statuses
26
47
  controllers.each_with_object({}) { |controller, statuses| statuses[controller.app_name] = controller.status }
27
48
  end
28
49
 
29
- def self.start(app_name)
50
+ def start(app_name)
30
51
  controller(app_name).start
31
52
  end
32
53
 
33
- def self.stop(app_name)
54
+ def stop(app_name)
34
55
  controller(app_name).stop
35
56
  end
36
57
  end
@@ -1,5 +1,5 @@
1
1
  module Daemons
2
2
  module Rails
3
- VERSION = "1.1.0.alpha"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -2,8 +2,6 @@
2
2
  require 'rubygems'
3
3
  require "daemons"
4
4
  require "daemons/rails/config"
5
- require "daemons/rails"
6
5
 
7
- config = Daemons::Rails::Config.new("<%= file_name %>", Daemons::Rails.configuration.root, Daemons::Rails.configuration.daemons_directory)
8
-
9
- Daemons.run File.dirname(__FILE__) + "/<%= file_name %>.rb", config.to_hash
6
+ config = Daemons::Rails::Config.for_controller(File.expand_path(__FILE__))
7
+ Daemons.run config[:script], config.to_hash
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+ require "daemons/rails/config"
3
+
4
+ describe Daemons::Rails::Config do
5
+ describe "daemon controller config" do
6
+ subject { Daemons::Rails::Config.for_controller(Rails.root.join('app', 'daemons', 'test_ctl').to_s) }
7
+
8
+ it "should init options" do
9
+ subject[:script].should == Rails.root.join('app', 'daemons', 'test.rb').to_s
10
+ end
11
+ end
12
+ end
@@ -10,7 +10,7 @@ describe Daemons::Rails::Configuration do
10
10
  describe "rails env" do
11
11
  its(:root) { should == Rails.root }
12
12
  its(:daemons_path) { should == Rails.root.join('lib', 'daemons') }
13
- its(:daemons_directory) { should == Pathname.new('lib').join('daemons') }
13
+ its(:daemons_path) { should == Pathname.new('lib').join('daemons') }
14
14
  end
15
15
 
16
16
  describe "no rails" do
@@ -26,7 +26,7 @@ describe Daemons::Rails::Configuration do
26
26
  end
27
27
  its(:root) { should == Rails_.root }
28
28
  its(:daemons_path) { should == Rails_.root.join('lib', 'daemons') }
29
- its(:daemons_directory) { should == Pathname.new('lib').join('daemons') }
29
+ its(:daemons_path) { should == Pathname.new('lib').join('daemons') }
30
30
  end
31
31
  end
32
32
 
@@ -42,10 +42,10 @@ describe Daemons::Rails::Configuration do
42
42
  end
43
43
 
44
44
  its(:daemons_path) { should == Rails.root.join('daemons') }
45
- its(:daemons_directory) { should == Pathname.new('daemons') }
45
+ its(:daemons_path) { should == Pathname.new('daemons') }
46
46
 
47
47
  it "should override daemons directory" do
48
- Daemons::Rails::Monitoring.daemons_directory.should == Rails.root.join('daemons')
48
+ Daemons::Rails::Monitoring.daemons_path.should == Rails.root.join('daemons')
49
49
  Daemons::Rails::Monitoring.controllers.map(&:app_name).should == %w(test2.rb)
50
50
  end
51
51
  end
@@ -3,35 +3,39 @@ require "daemons/rails/monitoring"
3
3
  require "ostruct"
4
4
 
5
5
  describe Daemons::Rails::Monitoring do
6
- subject { Daemons::Rails::Monitoring }
6
+ [Daemons::Rails::Monitoring, Daemons::Rails::Monitoring.new(Rails.root.join('lib', 'daemons'))].each do |subject|
7
+ it "should get list of controllers" do
8
+ controllers = subject.controllers
9
+ controllers.should have(1).item
10
+ controller = controllers[0]
11
+ controller.path.should == Rails.root.join('lib', 'daemons', 'test_ctl')
12
+ controller.app_name.should == 'test.rb'
13
+ end
7
14
 
8
- it "should get list of controllers" do
9
- controllers = subject.controllers
10
- controllers.should have(1).item
11
- controller = controllers[0]
12
- controller.path.should == Rails.root.join('lib', 'daemons', 'test_ctl')
13
- controller.app_name.should == 'test.rb'
14
- end
15
+ describe "using controllers" do
16
+ before :each do
17
+ @controller = Daemons::Rails::Controller.new(Rails.root.join('lib', 'daemons', 'test_ctl'))
18
+ Daemons::Rails::Monitoring.any_instance.stub(:controllers).and_return([@controller])
19
+ end
15
20
 
16
- describe "using controllers" do
17
- before :each do
18
- @controller = Daemons::Rails::Controller.new(Rails.root.join('lib', 'daemons', 'test_ctl'))
19
- subject.stub(:controllers).and_return([@controller])
20
- end
21
+ it "should return status for all controllers" do
22
+ @controller.should_receive(:run).with('status').and_return('test.rb: running [pid 10880]')
23
+ subject.statuses.should == {'test.rb' => :running}
24
+ end
21
25
 
22
- it "should return status for all controllers" do
23
- @controller.should_receive(:run).with('status').and_return('test.rb: running [pid 10880]')
24
- subject.statuses.should == {'test.rb' => :running}
25
- end
26
+ it "should start controller by name" do
27
+ @controller.should_receive(:run).with('start')
28
+ subject.start('test.rb')
29
+ end
26
30
 
27
- it "should start controller by name" do
28
- @controller.should_receive(:run).with('start')
29
- subject.start('test.rb')
31
+ it "should stop controller by name" do
32
+ @controller.should_receive(:run).with('stop')
33
+ subject.stop('test.rb')
34
+ end
30
35
  end
36
+ end
31
37
 
32
- it "should stop controller by name" do
33
- @controller.should_receive(:run).with('stop')
34
- subject.stop('test.rb')
35
- end
38
+ it "should monitor daemons in other than default directory" do
39
+ Daemons::Rails::Monitoring.new(Rails.root.join('daemons')).controllers.map(&:app_name).should == %w(test2.rb)
36
40
  end
37
41
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemons-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.alpha
5
- prerelease: 6
4
+ version: 1.1.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - mirasrael
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-03 00:00:00.000000000 Z
12
+ date: 2012-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -124,6 +124,7 @@ files:
124
124
  - spec/fixtures/daemons/test2_ctl
125
125
  - spec/fixtures/lib/daemons/test.rb
126
126
  - spec/fixtures/lib/daemons/test_ctl
127
+ - spec/lib/daemons/rails/config_spec.rb
127
128
  - spec/lib/daemons/rails/configuration_spec.rb
128
129
  - spec/lib/daemons/rails/monitoring_spec.rb
129
130
  - spec/spec_helper.rb
@@ -142,9 +143,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
143
  required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  none: false
144
145
  requirements:
145
- - - ! '>'
146
+ - - ! '>='
146
147
  - !ruby/object:Gem::Version
147
- version: 1.3.1
148
+ version: '0'
148
149
  requirements: []
149
150
  rubyforge_project:
150
151
  rubygems_version: 1.8.24