lib/poolparty.rb in auser-poolparty-0.0.9 vs lib/poolparty.rb in auser-poolparty-0.1.0
- old
+ new
@@ -1,54 +1,56 @@
=begin rdoc
The main file, contains the client and the server application methods
=end
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
+$TRACE = true
+
# rubygems
require 'rubygems'
require "aws/s3"
-require "sqs"
require "EC2"
require "aska"
require 'sprinkle'
-
-require 'thread'
require "pp"
require "tempfile"
begin
require 'fastthread'
require 'system_timer'
@@timer = SystemTimer
rescue LoadError
+ require 'thread'
require 'timeout'
@@timer = Timeout
end
## Load PoolParty
pwd = File.dirname(__FILE__)
# Load the required files
# If there is an init file, load that, otherwise
# require all the files in each directory
-%w(core modules s3 poolparty).each do |dir|
+%w(core modules s3 helpers poolparty).each do |dir|
Dir["#{pwd}/#{dir}"].each do |dir|
begin
require File.join(dir, "init")
rescue LoadError => e
Dir["#{pwd}/#{File.basename(dir)}/**"].each {|file| require File.join(dir, File.basename(file))}
end
end
end
module PoolParty
- module Version #:nodoc:
+ class Version #:nodoc:
@major = 0
- @minor = 0
- @tiny = 9
+ @minor = 1
+ @tiny = 0
- STRING = [@major, @minor, @tiny].join('.')
+ def self.string
+ [@major, @minor, @tiny].join('.')
+ end
end
def timer
@@timer
end
# PoolParty options
@@ -67,32 +69,48 @@
def root_dir
File.expand_path(File.dirname(__FILE__) + "/..")
end
# User directory
def user_dir
- Dir.pwd
+ Application.working_directory
end
# Write string to a tempfile
def write_to_temp_file(str="")
tempfile = Tempfile.new("rand#{rand(1000)}-#{rand(1000)}")
tempfile.print(str)
tempfile.flush
tempfile
end
def register_monitor(*names)
names.each do |name|
- PoolParty::Monitors.extend name
+ unless registered_monitor?(name)
+ PoolParty::Monitors.extend name
- PoolParty::Master.send :include, name::Master
- PoolParty::RemoteInstance.send :include, name::Remote
+ PoolParty::Master.send :include, name::Master
+ PoolParty::RemoteInstance.send :include, name::Remote
+
+ registered_monitors << name
+ end
end
end
+ def registered_monitor?(name); registered_monitors.include?(name); end
+ def registered_monitors; @@registered_monitors ||= [];end
+
+ def load
+ load_monitors
+ load_plugins
+ end
+ def load_monitors
+ loc = File.directory?("#{user_dir}/monitors") ? "#{user_dir}/monitors" : "#{root_dir}/lib/poolparty/monitors"
+ Dir["#{loc}/*"].each {|f| require f}
+ end
+
def load_plugins
Dir["#{plugin_dir}/**/init.rb"].each {|a| require a} if File.directory?(plugin_dir)
end
def reset!
+ @@registered_monitors = nil
@@installed_plugins = nil
- Application.options = nil
end
def plugin_dir
"#{user_dir}/vendor"
end
def read_config_file(filename)
\ No newline at end of file