lib/speed_gun.rb in speed_gun-0.0.4 vs lib/speed_gun.rb in speed_gun-1.0.0.rc1

- old
+ new

@@ -1,52 +1,43 @@ +require 'forwardable' require 'thread' +require 'speed_gun/version' +require 'speed_gun/config' +require 'speed_gun/profile' +require 'speed_gun/middleware' module SpeedGun class << self - attr_writer :config - end + # @return [SpeedGun::Config] the config of speed gun + def config + @config ||= Config.new + end - def self.current - Thread.current[:speed_gun_current] - end + # @return [SpeedGun::Profile, nil] the profile of a current thread + def current_profile + Thread.current[:speed_gun_current_profile] + end - def self.current=(profiler) - Thread.current[:speed_gun_current] = profiler - end + # Set the profile of a current thread + # + # @param profile [SpeedGun::Profile] the profile + # @return [SpeedGun::Profile] the profile of a current thread + def current_profile=(profile) + Thread.current[:speed_gun_current_profile] = profile + end - def self.config - @config ||= SpeedGun::Config.new - end + # Discard the profile of a current thread + # + # @return [nil] + def discard_profile! + self.current_profile = nil + end - def self.active? - current && current.active? - end - - def self.activate! - current && current.activate! - end - - def self.deactivate! - current && current.deactivate! - end - - def self.enable? - config.enable? - end - - def self.store - config.store - end - - def self.profile(title, *args, &block) - if title.kind_of?(String) - current && current.profile(:manual, title, &block) - else - current && current.profile(title, *args, &block) + # @see SpeedGun::Config#enabled? + # @return [Boolean] true if enabled speed gun + def enabled? + config.enabled? end end end -require 'speed_gun/version' -require 'speed_gun/config' -require 'speed_gun/middleware' require 'speed_gun/railtie' if defined?(Rails)