Module: Kernel

Defined in:
lib/tdriver/util/common/kernel.rb

Overview

Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Contact: Nokia Corporation ([email protected])

This file is part of Testability Driver.

If you have questions regarding the use of this file, please contact Nokia at [email protected] .

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation and appearing in the file LICENSE.LGPL included in the packaging of this file.

Instance Method Summary collapse

Instance Method Details

#__method_path__Object

TODO: document me



24
25
26
27
28
29
30
31
32
# File 'lib/tdriver/util/common/kernel.rb', line 24

def __method_path__

  # retrieve filename, line number and method name
  /^(.+?):(\d+)(?::in `(.*)')?/.match( caller.reverse[ -2 ].to_s )

  # construct string with module/class and method name
  "#{ ( [ Class, Module ].include?( self.class ) ? self.name : self.class.name ).to_s }##{ caller.first.to_s.scan(/`(.+)'$/).to_s }"

end

#warn_caller(message, remove_eval = true) ⇒ Object

TODO: document me

Raises:

  • (TypeError)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tdriver/util/common/kernel.rb', line 35

def warn_caller( message, remove_eval = true )

  # verify that message argument type is correct
  raise TypeError, "wrong argument type #{ message.class } for message (expected String)" unless message.kind_of?( String )

  # verify that remove_eval argument type is correct
  raise TypeError, "wrong argument type #{ remove_eval.class } for remove evaluate calls value (expected TrueClass or FalseClass)" unless [ TrueClass, FalseClass ].include?( remove_eval.class )

  # retrieve caller method, file and line number
  begin

    # remove evals if required
    caller_stack = ( remove_eval == true ? caller.select{ | str | str !~ /^\(eval\)\:/ and str !~ /`eval'$/ } : caller )

    # retrieve filename, line number and method name
    /^(.+?):(\d+)(?::in `(.*)')?/.match( caller_stack.reverse[ -2 ].to_s )

    # store matches
    file, line, method = $1, $2, $3

  rescue

    # could not retrieve filename, line number and method name
    file, line, method = [ '##', '##', 'unknown' ]

  end 

  # print warning to STDOUT
  warn message.gsub( '$1', file.to_s ).gsub( '$2', line.to_s ).gsub( '$3', method.to_s )

end