lib/speed_gun.rb in speed_gun-1.0.0.rc1 vs lib/speed_gun.rb in speed_gun-2.0.0.pre.alpha.1
- old
+ new
@@ -1,43 +1,38 @@
-require 'forwardable'
-require 'thread'
+# frozen_string_literal: true
require 'speed_gun/version'
require 'speed_gun/config'
-require 'speed_gun/profile'
-require 'speed_gun/middleware'
+require 'speed_gun/report'
+require 'rack/speed_gun'
+require 'speed_gun/railtie' if defined?(::Rails)
module SpeedGun
class << self
- # @return [SpeedGun::Config] the config of speed gun
+ # @return [SpeedGun::Config]
def config
- @config ||= Config.new
+ @config ||= SpeedGun::Config.new
end
- # @return [SpeedGun::Profile, nil] the profile of a current thread
- def current_profile
- Thread.current[:speed_gun_current_profile]
+ # @yield [config] Configure speed gun
+ # @yieldparam config [SpeedGun::Config]
+ def configure
+ yield config
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
+ # @return [SpeedGun::Report, nil]
+ def current_report
+ Thread.current[:speed_gun_report]
end
- # Discard the profile of a current thread
- #
- # @return [nil]
- def discard_profile!
- self.current_profile = nil
+ def current_report=(report)
+ Thread.current[:speed_gun_report] = report
end
- # @see SpeedGun::Config#enabled?
- # @return [Boolean] true if enabled speed gun
- def enabled?
- config.enabled?
+ def record(event)
+ current_report && current_report.record(event)
end
+
+ def get_report(id)
+ config.store.load("SpeedGun::Report/#{id}")
+ end
end
end
-
-require 'speed_gun/railtie' if defined?(Rails)