Module: Instana::Util
- Defined in:
- lib/instana/util.rb
Class Method Summary collapse
-
.enforce_deltas(candidate, last) ⇒ Object
Take two hashes, and make sure candidate does not have any of the same values as ‘last`.
-
.method_alias(klass, method) ⇒ Object
An agnostic approach to method aliasing.
-
.pry! ⇒ Object
Debugging helper method.
Class Method Details
.enforce_deltas(candidate, last) ⇒ Object
Take two hashes, and make sure candidate does not have any of the same values as ‘last`. We only report when values change.
Note this is not recursive, so only pass in the single hashes that you want delta reporting with.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/instana/util.rb', line 31 def enforce_deltas(candidate, last) return unless last.is_a?(Hash) candidate.each do |k,v| if candidate[k] == last[k] candidate.delete(k) end end candidate end |
.method_alias(klass, method) ⇒ Object
An agnostic approach to method aliasing.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/instana/util.rb', line 9 def method_alias(klass, method) if klass.method_defined?(method.to_sym) with = "#{method}_with_instana" without = "#{method}_without_instana" klass.class_eval do alias_method without, method.to_s alias_method method.to_s, with end else ::Instana.logger.debug "No such method (#{method}) to alias on #{klass}" end end |
.pry! ⇒ Object
Debugging helper method
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/instana/util.rb', line 44 def pry! # Only valid for development or test environments #env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] #return unless %w(development, test).include? env if RUBY_VERSION > '1.8.7' require 'pry-byebug' if defined?(PryByebug) Pry.commands.alias_command 'c', 'continue' Pry.commands.alias_command 's', 'step' Pry.commands.alias_command 'n', 'next' Pry.commands.alias_command 'f', 'finish' Pry::Commands.command(/^$/, 'repeat last command') do _pry_.run_command Pry.history.to_a.last end end binding.pry else require 'ruby-debug'; debugger end end |