Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/halorgium/nanite

* 'master' of git://github.com/halorgium/nanite:
  Register actors in the init.rb for agents to allow actors to not be auto-loaded if needed
  • Loading branch information...
commit ab30c0cec0bc950cdc761754a280258fa80afa92 2 parents 51d4185 + 6b6139b
Ezra Zygmuntowicz authored
View
4 examples/cli.rb
@@ -1,8 +1,6 @@
#!/usr/bin/env ruby
-require 'rubygems'
-require 'nanite'
-require 'nanite/mapper'
+require File.dirname(__FILE__) + '/../lib/nanite'
# cli.rb
#
View
13 examples/rack-worker/actors/rack_worker.rb
@@ -1,20 +1,11 @@
class RackWorker < Nanite::Actor
-
expose :call
-
+
def initialize(app)
@app = app
end
-
+
def call(env)
@app.call(env)
end
-
end
-
-app = Proc.new do |env|
- [200, {'Content-Type'=>'text/html'}, "hello world!"]
-end
-
-Nanite.register(RackWorker.new(app), 'rack')
-
View
4 examples/rack-worker/config.yml
@@ -1,5 +1,5 @@
----
+---
:pass: testing
:vhost: /nanite
:user: nanite
-:identity: fred
+:identity: fred
View
5 examples/rack-worker/init.rb
@@ -0,0 +1,5 @@
+app = Proc.new do |env|
+ [200, {'Content-Type'=>'text/html'}, "hello world!"]
+end
+
+register(RackWorker.new(app), 'rack')
View
5 examples/simpleagent/actors/simple.rb
@@ -1,7 +1,6 @@
# you can execute this nanite from the cli.rb command line example app
class Simple < Nanite::Actor
-
expose :echo, :time, :gems
def echo(payload)
@@ -15,8 +14,4 @@ def time(payload)
def gems(filter)
::Gem.source_index.refresh!.search(filter).flatten.collect {|gemspec| "#{gemspec.name} #{gemspec.version}"}
end
-
end
-
-Nanite.register(Simple.new)
-
View
3  lib/nanite.rb
@@ -29,8 +29,7 @@ class << self
# Registers actor instance with given prefix
def register(actor_instance, prefix = nil)
- @agent.log.info "Registering #{actor_instance.inspect} with prefix #{prefix.inspect}"
- @agent.dispatcher.register(actor_instance, prefix)
+ @agent.register(actor_instance, prefix)
end
# Initializes a new agent and establishes
View
11 lib/nanite/agent.rb
@@ -39,14 +39,15 @@ def start_console
# Nanite looks for actors under app_root/actors directory.
def load_actors
return unless root
- if File.exist?(root / 'init.rb')
- instance_eval(File.read(root / 'init.rb'), root / 'init.rb')
- end
Dir["#{root}/actors/*.rb"].each do |actor|
log.info "loading actor: #{actor}"
require actor
end
+
+ if File.exist?(root / 'init.rb')
+ instance_eval(File.read(root / 'init.rb'), root / 'init.rb')
+ end
end
# Log level used, defaults to INFO.
@@ -145,6 +146,10 @@ def start
start_console if opts[:console] && !opts[:daemonize]
end
+ def register(actor_instance, prefix = nil)
+ dispatcher.register(actor_instance, prefix)
+ end
+
# Updates last ping time
def pinged!
@last_ping = Time.now
View
1  lib/nanite/dispatcher.rb
@@ -21,6 +21,7 @@ def initialize(agent)
def register(actor_instance, prefix = nil)
raise ArgumentError, "#{actor_instance.inspect} is not a Nanite::Actor subclass instance" unless Nanite::Actor === actor_instance
+ @agent.log.info "Registering #{actor_instance.inspect} with prefix #{prefix.inspect}"
prefix ||= actor_instance.class.default_prefix
@actors[prefix.to_s] = actor_instance
end

0 comments on commit ab30c0c

Please sign in to comment.
Something went wrong with that request. Please try again.