lib/stella.rb in stella-0.6.0 vs lib/stella.rb in stella-0.7.0.002
- old
+ new
@@ -1,119 +1,73 @@
-require 'date'
-require 'time'
-require 'rubygems'
-require 'logger'
-require 'uri'
-require 'httpclient'
+unless defined?(STELLA_LIB_HOME)
+ STELLA_LIB_HOME = File.expand_path File.dirname(__FILE__)
+end
+local_libs = %w{drydock storable sysinfo gibbler}
+local_libs.each { |dir| $:.unshift File.join(STELLA_LIB_HOME, '..', '..', dir, 'lib') }
+#require 'rubygems'
+
require 'storable'
-require 'stella/stats'
+require 'sysinfo'
+require 'gibbler'
+require 'gibbler/aliases'
+require 'ostruct'
require 'threadify'
-require 'timeunits'
+require 'drydock/screen'
-require 'stella/crypto'
+module Stella
+ VERSION = "0.7.0.002"
+ extend self
+ require 'stella/version'
+ require 'stella/exceptions'
+ require 'stella/utils'
+ require 'stella/stats'
+ require 'stella/mixins'
+ require 'stella/dsl'
+ require 'stella/engine'
+ require 'stella/testplan'
-require 'stella/common'
-
-require 'stella/data/http'
-require 'stella/data/domain'
-
-require 'stella/environment'
-require 'stella/clients'
-require 'stella/testrunner'
-require 'stella/testplan'
-require 'stella/loadtest'
-require 'stella/functest'
-
-srand
-
-# Common dependencies
-STELLA_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..'))
-$: << File.join(STELLA_HOME, 'vendor', 'useragent', 'lib')
-
-
-# A friend in performance testing.
-module Stella
-
- LOGGER = Logger.new(:debug_level=>0) unless defined? LOGGER
+ autoload :Utils, STELLA_LIB_HOME + "/stella/utils"
+ autoload :Data, STELLA_LIB_HOME + "/stella/data"
+ autoload :Config, STELLA_LIB_HOME + "/stella/config"
+ autoload :Client, STELLA_LIB_HOME + "/stella/client"
- module VERSION #:nodoc:
- MAJOR = 0.freeze unless defined? MAJOR
- MINOR = 6.freeze unless defined? MINOR
- TINY = 0.freeze unless defined? TINY
- def self.to_s
- [MAJOR, MINOR, TINY].join('.')
- end
- def self.to_f
- self.to_s.to_f
- end
- end
+ @@sysinfo = SysInfo.new.freeze
+
+ @@logger = Drydock::Screen
+ @@loglev = 1
+ # Puts +msg+ to +@@logger+
+ def li(*msg); msg.each { |m| @@logger.puts m } if !quiet? end
+ def li1(*msg); li *msg if @@loglev >= 1 end
+ def li2(*msg); li *msg if @@loglev >= 2 end
+ def li3(*msg); li *msg if @@loglev >= 3 end
+ def li4(*msg); li *msg if @@loglev >= 4 end
- def self.debug_level
- Stella::LOGGER.debug_level
+ # Puts +msg+ to +@@logger+ with "ERROR: " prepended
+ def le(*msg); @@logger.puts " " << msg.join("#{$/} ").color(:red); end
+ # Puts +msg+ to +@@logger+ if +Rudy.debug?+ returns true
+ def ld(*msg)
+ @@logger.puts "D: " << msg.join("#{$/}D: ") if debug?
end
- def self.debug_level=(level)
- Stella::LOGGER.debug_level = level
- end
+ def loglev; @@loglev; end
+ def loglev=(val); @@loglev = val; end
+ def sysinfo; @@sysinfo; end
- def self.info(*args)
- LOGGER.info(*args)
- end
+ def quiet?; @@loglev == 0; end
+ def enable_quiet; @@loglev = 0; end
+ def disable_quiet; @@loglev = 1; end
+
+ def debug?; @@loglev > 3; end
+ def enable_debug; @@loglev = 4; end
+ def disable_debug; @@loglev = 1; end
- def self.error(*args)
- LOGGER.error(*args)
+ def rescue(&blk)
+ blk.call
+ rescue => ex
+ Stella.le "ERROR: #{ex.message}"
+ Stella.ld ex.backtrace
end
-
- def self.fatal(*args)
- LOGGER.error(*args)
- exit 1
- end
-
- def self.debug(*args)
- LOGGER.debug(*args)
- end
end
-module Stella
- module DSL
- include Stella::DSL::TestPlan
- include Stella::DSL::FunctionalTest
- include Stella::DSL::LoadTest
- include Stella::DSL::Environment
- # For Modules
- #extend Stella::DSL::TestPlan
- #extend Stella::DSL::FunctionalTest
- end
-end
-
-class Object #:nodoc: all
-# The hidden singleton lurks behind everyone
- def metaclass; class << self; self; end; end
- def meta_eval &blk; metaclass.instance_eval &blk; end
-
- # Adds methods to a metaclass
- def meta_def name, &blk
- meta_eval { define_method name, &blk }
- end
-
- # Defines an instance method within a class
- def class_def name, &blk
- class_eval { define_method name, &blk }
- end
-
-end
-
-class Array
- # create a hash from an array of [key,value] tuples
- # you can set default or provide a block just as with Hash::new
- # Note: if you use [key, value1, value2, value#], hash[key] will
- # be [value1, value2, value#]
- # From: http://www.ruby-forum.com/topic/138218#615260
- def stella_to_hash(default=nil, &block)
- hash = block_given? ? Hash.new(&block) : Hash.new(default)
- each { |(key, *value)| hash[key]=*value }
- hash
- end
-end