Module: Oboe::Util

Defined in:
lib/oboe/util.rb,
lib/oboe/loading.rb

Defined Under Namespace

Modules: Base64URL

Class Method Summary collapse

Class Method Details

.method_alias(cls, method, name = nil) ⇒ Object

method_alias

Centralized utility method to alias a method on an arbitrary class or module.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oboe/util.rb', line 13

def method_alias(cls, method, name=nil)
  # Attempt to infer a contextual name if not indicated
  #
  # For example:
  # ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.to_s.split(/::/).last
  # => "AbstractMysqlAdapter"
  #
  begin
    name ||= cls.to_s.split(/::/).last 
  rescue
  end

  if cls.method_defined? method.to_sym or cls.private_method_defined? method.to_sym
    
    # Strip '!' or '?' from method if present
    safe_method_name = method.to_s.chop if method.to_s =~ /\?$|\!$/
    safe_method_name ||= method

    without_oboe = "#{safe_method_name}_without_oboe"
    with_oboe    = "#{safe_method_name}_with_oboe"
 
    # Only alias if we haven't done so already
    unless cls.method_defined? without_oboe.to_sym or 
      cls.private_method_defined? without_oboe.to_sym

      cls.class_eval do
        alias_method without_oboe, "#{method}"
        alias_method "#{method}", with_oboe
      end
    end
  else Oboe.logger.warn "[oboe/loading] Couldn't properly instrument #{name}.  Partial traces may occur."
  end
end

.prettify(x) ⇒ Object

prettify

Even to my surprise, ‘prettify’ is a real word: transitive v. To make pretty or prettier, especially in a superficial or insubstantial way.

from The American Heritage® Dictionary of the English Language, 4th Edition

This method makes things ‘purty’ for reporting.



76
77
78
79
80
81
82
# File 'lib/oboe/util.rb', line 76

def prettify(x)
  if (x.to_s =~ /^#</) == 0
    x.class.to_s
  else
    x.to_s
  end
end

.send_include(target_cls, cls) ⇒ Object

send_include

Centralized utility method to send a include call for an arbitrary class



52
53
54
55
56
# File 'lib/oboe/util.rb', line 52

def send_include(target_cls, cls)
  if defined?(target_cls)
    target_cls.send(:include, cls)
  end
end

.static_asset?(path) ⇒ Boolean

static_asset?

Given a path, this method determines whether it is a static asset or not (based solely on filename)

Returns:

  • (Boolean)


64
65
66
# File 'lib/oboe/util.rb', line 64

def static_asset?(path)
  return (path =~ /\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|ttf|woff|svg|less)$/i)
end