daemon-kit 0.1.3 → 0.1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.1.5 2009-05-07
2
+
3
+ * DaemonKit::Config class to easy the use of YAML configs internally,
4
+ and in generated daemons
5
+
1
6
  == 0.1.2 2009-04-28
2
7
 
3
8
  * Added missing rubigen dependency
data/Manifest.txt CHANGED
@@ -15,6 +15,7 @@ app_generators/daemon_kit/templates/config/environments/development.rb
15
15
  app_generators/daemon_kit/templates/config/environments/production.rb
16
16
  app_generators/daemon_kit/templates/config/environments/test.rb
17
17
  app_generators/daemon_kit/templates/config/initializers/readme
18
+ app_generators/daemon_kit/templates/lib/daemon.rb
18
19
  app_generators/daemon_kit/templates/libexec/daemon.erb
19
20
  bin/daemon_kit
20
21
  daemon_generators/amqp/USAGE
@@ -31,12 +32,21 @@ daemon_generators/jabber/jabber_generator.rb
31
32
  daemon_generators/jabber/templates/config/initializers/jabber.rb
32
33
  daemon_generators/jabber/templates/config/jabber.yml
33
34
  daemon_generators/jabber/templates/libexec/daemon.rb
35
+ daemon_generators/nanite_agent/USAGE
36
+ daemon_generators/nanite_agent/nanite_agent_generator.rb
37
+ daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb
38
+ daemon_generators/nanite_agent/templates/config/nanite.yml
39
+ daemon_generators/nanite_agent/templates/lib/actors/sample.rb
40
+ daemon_generators/nanite_agent/templates/libexec/daemon.rb
34
41
  lib/daemon_kit.rb
35
42
  lib/daemon_kit/amqp.rb
36
43
  lib/daemon_kit/application.rb
44
+ lib/daemon_kit/config.rb
37
45
  lib/daemon_kit/cron.rb
38
46
  lib/daemon_kit/initializer.rb
39
47
  lib/daemon_kit/jabber.rb
48
+ lib/daemon_kit/nanite.rb
49
+ lib/daemon_kit/nanite/agent.rb
40
50
  lib/daemon_kit/patches/force_kill_wait.rb
41
51
  lib/daemon_kit/tasks.rb
42
52
  lib/daemon_kit/tasks/framework.rake
@@ -58,5 +68,8 @@ tasks/rspec.rake
58
68
  test/test_amqp_generator.rb
59
69
  test/test_cron_generator.rb
60
70
  test/test_daemon-kit_generator.rb
71
+ test/test_daemon_kit_config.rb
61
72
  test/test_generator_helper.rb
73
+ test/test_helper.rb
62
74
  test/test_jabber_generator.rb
75
+ test/test_nanite_agent_generator.rb
data/TODO.txt CHANGED
@@ -3,7 +3,7 @@ DaemonKit TODO List
3
3
 
4
4
  This is purely a drop in the bucket of what has to come...
5
5
 
6
- * [DONE] Easy way to trap signals
6
+ * [DONE] Easy way to trap signals
7
7
  * Error handling to the degree Rails does
8
8
  * Easy configuration of an ORM of choice, including patching it if needed (ActiveRecord *cough*)
9
9
  * Improved generators for creating skeleton daemons:
@@ -20,5 +20,12 @@ This is purely a drop in the bucket of what has to come...
20
20
  * Improved and cleaned up logging
21
21
  * Plenty of docs, seriously a lot of docs
22
22
  * Specs & features, tons of them too
23
+ * Integration tests for the specific daemons
23
24
  * Some level of thread safety, or mechanisms to ease thread safety
25
+ * Built in utilities:
26
+ * Thread pool for 1.8
27
+ * Fibre pool for 1.9
28
+ * Some activesupport-esque functions until activesupport 3.0 hits the streets
29
+ * DRY up the following:
30
+ * Loading configuration files for the daemons
24
31
  * DON'T FORGET 1.9 SUPPORT
@@ -3,8 +3,8 @@ class DaemonKitGenerator < RubiGen::Base
3
3
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
4
  Config::CONFIG['ruby_install_name'])
5
5
 
6
- VALID_GENERATORS = ['default', 'jabber', 'cron', 'amqp']
7
-
6
+ VALID_GENERATORS = ['default', 'jabber', 'cron', 'amqp', 'nanite_agent']
7
+
8
8
  default_options :shebang => DEFAULT_SHEBANG, :author => nil
9
9
 
10
10
  attr_reader :daemon_name
@@ -25,9 +25,9 @@ class DaemonKitGenerator < RubiGen::Base
25
25
  $stderr.puts "Valid generators are: #{VALID_GENERATORS.join(', ')}"
26
26
  exit 1
27
27
  end
28
-
28
+
29
29
  script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
30
-
30
+
31
31
  record do |m|
32
32
  # Ensure appropriate folder(s) exists
33
33
  m.directory ''
@@ -37,11 +37,11 @@ class DaemonKitGenerator < RubiGen::Base
37
37
  # m.template_copy_each ["template.rb", "template2.rb"]
38
38
  # m.file "file", "some_file_copied"
39
39
  # m.file_copy_each ["path/to/file", "path/to/file2"]
40
-
40
+
41
41
  # Readme
42
42
  m.template "README", "README"
43
43
  m.template "Rakefile", "Rakefile"
44
-
44
+
45
45
  # Executable
46
46
  m.directory "bin"
47
47
  m.template "bin/daemon.erb", "bin/#{daemon_name}", script_options
@@ -49,7 +49,7 @@ class DaemonKitGenerator < RubiGen::Base
49
49
  # Generator
50
50
  if installer == "default"
51
51
  m.directory "libexec"
52
- m.template "libexec/daemon.erb", "libexec/#{daemon_name}.rb"
52
+ m.template "libexec/daemon.erb", "libexec/#{daemon_name}-daemon.rb"
53
53
  else
54
54
  m.dependency installer, [daemon_name], :destination => destination_root, :collision => :force
55
55
  end
@@ -65,7 +65,8 @@ class DaemonKitGenerator < RubiGen::Base
65
65
 
66
66
  # Libraries
67
67
  m.directory "lib"
68
-
68
+ m.file "lib/daemon.rb", "lib/#{daemon_name}.rb"
69
+
69
70
  # Tests
70
71
  m.directory "tasks"
71
72
  m.dependency "install_rspec", [daemon_name], :destination => destination_root, :collision => :force
@@ -4,4 +4,4 @@
4
4
 
5
5
  require File.dirname(__FILE__) + '/../config/environment'
6
6
 
7
- DaemonKit::Application.run( DAEMON_ROOT + '/libexec/<%= daemon_name %>.rb' )
7
+ DaemonKit::Application.run( DAEMON_ROOT + '/libexec/<%= daemon_name %>-daemon.rb' )
@@ -0,0 +1 @@
1
+ # Your starting point for daemon specific classes
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,68 @@
1
+ class NaniteAgentGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ usage if args.empty?
10
+ @name = args.shift
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.directory ''
18
+
19
+ # Create stubs
20
+ # m.template "template.rb.erb", "some_file_after_erb.rb"
21
+ # m.template_copy_each ["template.rb", "template2.rb"]
22
+ # m.template_copy_each ["template.rb", "template2.rb"], "some/path"
23
+ # m.file "file", "some_file_copied"
24
+ # m.file_copy_each ["path/to/file", "path/to/file2"]
25
+ # m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
26
+
27
+ # Copy over our configs
28
+ m.directory 'lib'
29
+ m.directory 'lib/actors'
30
+ m.file 'lib/actors/sample.rb', 'lib/actors/sample.rb'
31
+ m.directory 'config'
32
+ m.template 'config/nanite.yml', 'config/nanite.yml'
33
+ m.directory 'config/initializers'
34
+ m.template 'config/initializers/nanite_agent.rb', "config/initializers/#{name}.rb"
35
+
36
+ # Copy over our daemon
37
+ m.directory 'libexec'
38
+ m.template 'libexec/daemon.rb', "libexec/#{name}.rb"
39
+ end
40
+ end
41
+
42
+ protected
43
+ def banner
44
+ <<-EOS
45
+ Creates a ...
46
+
47
+ USAGE: #{$0} #{spec.name} name
48
+ EOS
49
+ end
50
+
51
+ def add_options!(opts)
52
+ # opts.separator ''
53
+ # opts.separator 'Options:'
54
+ # For each option below, place the default
55
+ # at the top of the file next to "default_options"
56
+ # opts.on("-a", "--author=\"Your Name\"", String,
57
+ # "Some comment about this option",
58
+ # "Default: none") { |o| options[:author] = o }
59
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
60
+ end
61
+
62
+ def extract_options
63
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
64
+ # Templates can access these value via the attr_reader-generated methods, but not the
65
+ # raw instance variable value.
66
+ # @author = options[:author]
67
+ end
68
+ end
@@ -0,0 +1,6 @@
1
+ begin
2
+ require 'nanite'
3
+ rescue LoadError
4
+ $stderr.puts "Missing nanite gem. Please run 'gem install nanite'."
5
+ exit 1
6
+ end
@@ -0,0 +1,35 @@
1
+ # Nanite agent configuration file
2
+
3
+ # These values will be used to configure the nanite agent, any values
4
+ # omitted will let the gem use it's own defaults.
5
+
6
+ # The configuration specifies the following keys:
7
+ # * user - Specify the rabbitmq username
8
+ # * pass - Specify the rabbitmq password
9
+ # * host - Specify the rabbitmq hostname
10
+ # * vhost - Specify the rabbitmq vhost
11
+ # * port - Specify the rabbitmq PORT, default 5672
12
+ # * token - Specify the agent identity
13
+ # * security - Use Security features of rabbitmq to restrict nanites to themselves
14
+ # * format - The serialization type to use for transfering data. Can be marshal, json or yaml. Default is marshal
15
+ # * tag - YAML array of tags
16
+ # * ping-time - Specify how often the agents contacts the mapper
17
+ # * actors - Comma separated list of actors to load (all ruby files in actors directory by default)
18
+
19
+ defaults: &defaults
20
+ username: nanite
21
+ password: testing
22
+ host: localhost
23
+ vhost: /nanite
24
+ # tag:
25
+ # - foo
26
+ # - bar
27
+
28
+ development:
29
+ <<: *defaults
30
+
31
+ test:
32
+ <<: *defaults
33
+
34
+ production:
35
+ <<: *defaults
@@ -0,0 +1,11 @@
1
+ class Sample
2
+ include Nanite::Actor
3
+
4
+ expose :echo
5
+
6
+ # Print to STDOUT and return
7
+ def echo( payload )
8
+ p payload
9
+ payload
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # Generated nanite agent daemon
2
+
3
+ # Do your post daemonization configuration here
4
+ # At minimum you need just the first line (without the block), or a lot
5
+ # of strange things might start happening...
6
+ DaemonKit::Application.running! do |config|
7
+ # Trap signals with blocks or procs
8
+ # config.trap( 'INT' ) do
9
+ # # do something clever
10
+ # end
11
+ # config.trap( 'TERM', Proc.new { puts 'Going down' } )
12
+ end
13
+
14
+ # IMPORTANT CONFIGURATION NOTE
15
+ #
16
+ # Please review and update 'config/nanite.yml' accordingly or this
17
+ # daemon won't work as advertised.
18
+ #
19
+ # Your actors live in DAEMON_ROOT/lib/actors
20
+
21
+ # Run the agent, and get the running agent.
22
+ DaemonKit::Nanite::Agent.run do |agent|
23
+ # Use the yielded agent instance to register your actors:
24
+ agent.register Sample.new
25
+
26
+ # This block can used to make your agent perform other tasks as
27
+ # well. Remember that you have access to a running EventMachine
28
+ # reactor since the AMQP gem used by nanite uses it. Other than that
29
+ # you can mostly leave this file alone and concentrate on developing
30
+ # your actors in the lib/actors/ directory of the project.
31
+ end
data/lib/daemon_kit.rb CHANGED
@@ -4,11 +4,13 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require 'rubygems'
5
5
 
6
6
  module DaemonKit
7
- VERSION = '0.1.3'
8
-
7
+ VERSION = '0.1.5.1'
8
+
9
9
  autoload :Initializer, 'daemon_kit/initializer'
10
10
  autoload :Application, 'daemon_kit/application'
11
+ autoload :Config, 'daemon_kit/config'
11
12
  autoload :Cron, 'daemon_kit/cron'
12
13
  autoload :Jabber, 'daemon_kit/jabber'
13
14
  autoload :AMQP, 'daemon_kit/amqp'
15
+ autoload :Nanite, 'daemon_kit/nanite'
14
16
  end
@@ -11,11 +11,7 @@ module DaemonKit
11
11
  class << self
12
12
 
13
13
  def instance
14
- @instance ||= (
15
- config = YAML.load_file( "#{DAEMON_ROOT}/config/amqp.yml" )[DAEMON_ENV]
16
- raise ArgumentError, "Missing AMQP configuration for #{DAEMON_ENV} environment" if config.nil?
17
- new( config )
18
- )
14
+ @instance ||= new
19
15
  end
20
16
 
21
17
  private :new
@@ -26,7 +22,7 @@ module DaemonKit
26
22
  end
27
23
 
28
24
  def initialize( config = {} )
29
- @config = config.inject({}) { |m,c| m[c[0].to_sym] = c[1]; m } # symbolize_keys
25
+ @config = DaemonKit::Config.load('amqp').to_h( true )
30
26
  end
31
27
 
32
28
  def run(&block)
@@ -0,0 +1,64 @@
1
+ module DaemonKit
2
+
3
+ # Simplify simple config file loading for daemons. Assumes the
4
+ # config files all live in DAEMON_ROOT/config and are YAML
5
+ # files. Loaded configs are accessed like a hash with string
6
+ # keys.
7
+ #
8
+ # Config files can either be keyed by environment (default behavior)
9
+ # or be a normal hash.
10
+ #
11
+ # Load a config by passing the filename (with or without the .yml
12
+ # extension) to #load.
13
+ #
14
+ # At this stage the configs are read-only.
15
+ #
16
+ # Any of the keys can be called as methods as well.
17
+ class Config
18
+
19
+ class << self
20
+
21
+ # Load the +config+.yml file from DAEMON_ROOT/config
22
+ def load( config )
23
+ config += '.yml' unless config =~ /\.yml$/
24
+
25
+ path = File.join( DAEMON_ROOT, 'config', config )
26
+
27
+ raise ArgumentError, "Can't find #{path}" unless File.exists?( path )
28
+
29
+ new( YAML.load_file( path ) )
30
+ end
31
+
32
+ end
33
+
34
+ # Expects a hash, looks for DAEMON_ENV key
35
+ def initialize( config_data ) #:nodoc:
36
+ if config_data.has_key?( DAEMON_ENV )
37
+ @data = config_data[ DAEMON_ENV ]
38
+ else
39
+ @data = config_data
40
+ end
41
+ end
42
+
43
+ # Pick out a config by name
44
+ def []( key )
45
+ @data[ key.to_s ]
46
+ end
47
+
48
+ # Return the internal hash structure used, optionally symbolizing
49
+ # the first level of keys in the hash
50
+ def to_h( symbolize = false )
51
+ symbolize ? @data.inject({}) { |m,c| m[c[0].to_sym] = c[1]; m } : @data
52
+ end
53
+
54
+ def method_missing( method_name, *args ) #:nodoc:
55
+ # don't match setters
56
+ unless method_name.to_s =~ /[\w_]+=$/
57
+ # pick a key if we have it
58
+ return @data[ method_name.to_s ] if @data.keys.include?( method_name.to_s )
59
+ end
60
+
61
+ super
62
+ end
63
+ end
64
+ end
@@ -12,28 +12,24 @@ module DaemonKit
12
12
  @@message_handler = nil
13
13
  @@presence_handler = nil
14
14
  @@subscription_handler = nil
15
-
15
+
16
16
  class << self
17
17
 
18
18
  # Deliver a message to the specified jid.
19
19
  def deliver( jid, message )
20
20
  instance.connection.deliver( jid, message )
21
21
  end
22
-
22
+
23
23
  # Use this instead of initializing, keeps it singleton
24
24
  def instance
25
- @instance ||= (
26
- config = YAML.load_file( "#{DAEMON_ROOT}/config/jabber.yml" )[DAEMON_ENV]
27
- raise ArgumentError, "Missing Jabber configuration for #{DAEMON_ENV} environment" if config.nil?
28
- new( config )
29
- )
25
+ @instance ||= new
30
26
  @instance.startup!
31
27
  end
32
28
  private :new
33
29
 
34
30
  def run
35
31
  DaemonKit.logger.info "Starting jabber loop"
36
-
32
+
37
33
  loop do
38
34
  process_messages
39
35
  process_updates
@@ -47,7 +43,7 @@ module DaemonKit
47
43
  end
48
44
  end
49
45
  end
50
-
46
+
51
47
  def process_messages
52
48
  @message_handler ||= Proc.new { |m| DaemonKit.logger.info "Received message from #{m.from}: #{m.body}" }
53
49
 
@@ -62,7 +58,7 @@ module DaemonKit
62
58
  instance.connection.presence_updates { |friend, old_presence, new_presence|
63
59
  @presence_handler.call(friend, old_presence, new_presence)
64
60
  }
65
-
61
+
66
62
  end
67
63
 
68
64
  def process_subscriptions
@@ -70,11 +66,11 @@ module DaemonKit
70
66
 
71
67
  instance.connection.subscription_requests { |friend,presence| @subscription_handler.call(friend,presence) }
72
68
  end
73
-
69
+
74
70
  def received_messages(&block)
75
71
  @message_handler = block
76
72
  end
77
-
73
+
78
74
  def presence_updates(&block)
79
75
  @presence_handler = block
80
76
  end
@@ -82,10 +78,12 @@ module DaemonKit
82
78
  def subscription_requests(&block)
83
79
  @subscription_handler = block
84
80
  end
85
-
81
+
86
82
  end
87
83
 
88
- def initialize( options = {} )
84
+ def initialize
85
+ options = DaemonKit::Config.load( 'jabber' )
86
+
89
87
  @jabber_id = options.delete("jabber_id")
90
88
  @password = options.delete("password")
91
89
  @resource = options.delete("resource") || 'daemon_kit'
@@ -103,7 +101,7 @@ module DaemonKit
103
101
 
104
102
  DaemonKit.trap( 'INT', Proc.new { self.shutdown! } )
105
103
  DaemonKit.trap( 'TERM', Proc.new { self.shutdown! } )
106
-
104
+
107
105
  @booted = true
108
106
 
109
107
  self
@@ -141,9 +139,9 @@ module DaemonKit
141
139
  def status_line
142
140
  "#{DaemonKit.configuration.daemon_name} ready for instructions"
143
141
  end
144
-
142
+
145
143
  private
146
-
144
+
147
145
  def connect!
148
146
  jid = @jabber_id + '/' + @resource
149
147
 
@@ -167,6 +165,6 @@ module DaemonKit
167
165
  end
168
166
  end
169
167
  end
170
-
168
+
171
169
  end
172
170
  end
@@ -0,0 +1,7 @@
1
+ module DaemonKit
2
+ # For building daemons that integrate with nanite, either as mappers
3
+ # or agents. See #DaemonKit::Nanite::Agent so far
4
+ module Nanite
5
+ autoload :Agent, "daemon_kit/nanite/agent"
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ module DaemonKit
2
+ module Nanite
3
+ # Pull support into a daemon for being a nanite agent.
4
+ class Agent
5
+
6
+ @@instance = nil
7
+
8
+ class << self
9
+
10
+ def instance
11
+ @instance ||= new
12
+ end
13
+
14
+ private :new
15
+
16
+ def run(&block)
17
+ instance.run(&block)
18
+ end
19
+
20
+ end
21
+
22
+ def initialize
23
+ @config = DaemonKit::Config.load( 'nanite' )
24
+
25
+ config_agent
26
+ end
27
+
28
+ def run(&block)
29
+ # Ensure graceful shutdown of the connection to the broker
30
+ DaemonKit.trap('INT') { ::EM.stop }
31
+ DaemonKit.trap('TERM') { ::EM.stop }
32
+
33
+ # Start our mapper
34
+ mapper_thread = Thread.new do
35
+ EM.run do
36
+ agent = ::Nanite.start_agent( @config.to_h( true ) )
37
+ block.call( agent ) if block
38
+ end
39
+ end
40
+
41
+ #block.call if block
42
+
43
+ mapper_thread.join
44
+ end
45
+
46
+ private
47
+
48
+ # Make sure to fine tune the agent config to be DK friendly
49
+ def config_agent
50
+ @config[:root] = DAEMON_ROOT
51
+ @config[:daemonize] = false
52
+ @config[:actors_dir] = File.join(DAEMON_ROOT, 'lib', 'actors')
53
+ end
54
+ end
55
+ end
56
+ end
@@ -8,3 +8,14 @@ end
8
8
 
9
9
  require File.dirname(__FILE__) + '/../config/boot'
10
10
  require '<%= gem_name %>'
11
+
12
+ Spec::Runner.configure do |config|
13
+ # == Mock Framework
14
+ #
15
+ # RSpec uses it's own mocking framework by default. If you prefer to
16
+ # use mocha, flexmock or RR, uncomment the appropriate line:
17
+ #
18
+ config.mock_with :mocha
19
+ # config.mock_with :flexmock
20
+ # config.mock_with :rr
21
+ end
@@ -43,8 +43,9 @@ class TestDaemonKitGenerator < Test::Unit::TestCase
43
43
  assert_directory_exists "config/initializers"
44
44
  assert_generated_file "config/initializers/readme"
45
45
  assert_directory_exists "lib"
46
+ assert_generated_file "lib/#{daemon_name}.rb"
46
47
  assert_directory_exists "libexec"
47
- assert_generated_file "libexec/#{daemon_name}.rb"
48
+ assert_generated_file "libexec/#{daemon_name}-daemon.rb"
48
49
  assert_directory_exists "log"
49
50
  assert_directory_exists "spec"
50
51
  assert_directory_exists "tasks"
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class TestDaemonKitConfig < Test::Unit::TestCase
4
+
5
+ def test_initialize_with_env_hash
6
+ data = {
7
+ 'test' => {
8
+ 'foo' => 'bar'
9
+ }
10
+ }
11
+
12
+ config = DaemonKit::Config.new( data )
13
+
14
+ assert_equal config['foo'], 'bar'
15
+ assert_equal config.foo, 'bar'
16
+ end
17
+
18
+ def test_initialize_without_env_hash
19
+ data = {
20
+ 'foo' => 'bar'
21
+ }
22
+
23
+ config = DaemonKit::Config.new( data )
24
+
25
+ assert_equal config['foo'], 'bar'
26
+ assert_equal config.foo, 'bar'
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ DAEMON_ENV = "test"
4
+
5
+ require File.dirname(__FILE__) + '/../lib/daemon_kit'
6
+
7
+
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+
3
+
4
+ class TestNaniteAgentGenerator < Test::Unit::TestCase
5
+ include RubiGen::GeneratorTestHelper
6
+
7
+ def setup
8
+ bare_setup
9
+ end
10
+
11
+ def teardown
12
+ bare_teardown
13
+ end
14
+
15
+ # Some generator-related assertions:
16
+ # assert_generated_file(name, &block) # block passed the file contents
17
+ # assert_directory_exists(name)
18
+ # assert_generated_class(name, &block)
19
+ # assert_generated_module(name, &block)
20
+ # assert_generated_test_for(name, &block)
21
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
22
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
23
+ #
24
+ # Other helper methods are:
25
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
26
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
27
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
28
+
29
+ def test_generator_without_options
30
+ name = "myapp"
31
+ run_generator('nanite_agent', [name], sources)
32
+ assert_directory_exists "lib/actors"
33
+ assert_generated_file "lib/actors/sample.rb"
34
+ assert_directory_exists "config"
35
+ assert_generated_file "config/nanite.yml"
36
+ assert_directory_exists "config/initializers"
37
+ assert_generated_file "config/initializers/myapp.rb"
38
+ end
39
+
40
+ private
41
+ def sources
42
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
43
+ ]
44
+ end
45
+
46
+ def generator_path
47
+ "daemon_generators"
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemon-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenneth Kalmer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-29 00:00:00 +02:00
12
+ date: 2009-05-08 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ files:
82
82
  - app_generators/daemon_kit/templates/config/environments/production.rb
83
83
  - app_generators/daemon_kit/templates/config/environments/test.rb
84
84
  - app_generators/daemon_kit/templates/config/initializers/readme
85
+ - app_generators/daemon_kit/templates/lib/daemon.rb
85
86
  - app_generators/daemon_kit/templates/libexec/daemon.erb
86
87
  - bin/daemon_kit
87
88
  - daemon_generators/amqp/USAGE
@@ -98,12 +99,21 @@ files:
98
99
  - daemon_generators/jabber/templates/config/initializers/jabber.rb
99
100
  - daemon_generators/jabber/templates/config/jabber.yml
100
101
  - daemon_generators/jabber/templates/libexec/daemon.rb
102
+ - daemon_generators/nanite_agent/USAGE
103
+ - daemon_generators/nanite_agent/nanite_agent_generator.rb
104
+ - daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb
105
+ - daemon_generators/nanite_agent/templates/config/nanite.yml
106
+ - daemon_generators/nanite_agent/templates/lib/actors/sample.rb
107
+ - daemon_generators/nanite_agent/templates/libexec/daemon.rb
101
108
  - lib/daemon_kit.rb
102
109
  - lib/daemon_kit/amqp.rb
103
110
  - lib/daemon_kit/application.rb
111
+ - lib/daemon_kit/config.rb
104
112
  - lib/daemon_kit/cron.rb
105
113
  - lib/daemon_kit/initializer.rb
106
114
  - lib/daemon_kit/jabber.rb
115
+ - lib/daemon_kit/nanite.rb
116
+ - lib/daemon_kit/nanite/agent.rb
107
117
  - lib/daemon_kit/patches/force_kill_wait.rb
108
118
  - lib/daemon_kit/tasks.rb
109
119
  - lib/daemon_kit/tasks/framework.rake
@@ -125,8 +135,11 @@ files:
125
135
  - test/test_amqp_generator.rb
126
136
  - test/test_cron_generator.rb
127
137
  - test/test_daemon-kit_generator.rb
138
+ - test/test_daemon_kit_config.rb
128
139
  - test/test_generator_helper.rb
140
+ - test/test_helper.rb
129
141
  - test/test_jabber_generator.rb
142
+ - test/test_nanite_agent_generator.rb
130
143
  has_rdoc: true
131
144
  homepage:
132
145
  post_install_message: |+
@@ -161,8 +174,11 @@ signing_key:
161
174
  specification_version: 2
162
175
  summary: Daemon Kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code.
163
176
  test_files:
164
- - test/test_daemon-kit_generator.rb
165
177
  - test/test_generator_helper.rb
166
178
  - test/test_jabber_generator.rb
167
179
  - test/test_cron_generator.rb
168
180
  - test/test_amqp_generator.rb
181
+ - test/test_nanite_agent_generator.rb
182
+ - test/test_daemon-kit_generator.rb
183
+ - test/test_daemon_kit_config.rb
184
+ - test/test_helper.rb