Module | RubyRunUtils__ |
In: |
lib/rubyrun/rubyrun_utils__.rb
|
Environment variable not defined or defined with nil value is deemed to be non-existent
# File lib/rubyrun/rubyrun_utils__.rb, line 33 33: def env_var_exists?(var) 34: ENV[var].nil? || ENV[var] == '' ? false : true 35: end
Error exit
# File lib/rubyrun/rubyrun_utils__.rb, line 38 38: def fatal_exit(e) 39: $stderr.print e.to_s + "\n" + e.backtrace.join("\n") 40: exit(-1) 41: end
Retrieve caller details (filename, line number, method name)
# File lib/rubyrun/rubyrun_utils__.rb, line 27 27: def get_caller_detail(n=3) 28: caller(0)[n].gsub("#{RUBYRUN_PREFIX}_", '').gsub('//', '/') 29: end
Return a readable thread ID for the current thread of execution
# File lib/rubyrun/rubyrun_utils__.rb, line 22 22: def get_thread_id(th=Thread.current) 23: th.inspect.split(/Thread:0x/)[1].split(/ .*?>/)[0] 24: end
Given a class, it‘s deemed to be a Rails Action Controller if one of its ancestors is ApplicationController
# File lib/rubyrun/rubyrun_utils__.rb, line 60 60: def is_application_controller(klass) 61: return false unless klass.superclass 62: if klass.superclass == ApplicationController 63: return true 64: else 65: is_application_controller(klass.superclass) 66: end 67: end
Return false if the passed in hash is empty Return false if the hash doenst even have the class name as a key Return true if the hash has the key but the method array is empty Return true if the method array has a case-insensitive matching name, matching can be exact or ‘include’. Otherwise return false
# File lib/rubyrun/rubyrun_utils__.rb, line 75 75: def is_in?(hash, klass, mid, mode='loose') 76: return false if hash.empty? 77: [klass.to_s, klass.class.to_s, '*'].each {|name| 78: if hash.has_key?(name) 79: return true if hash[name].empty? 80: method_name = return_method_name(mid) 81: hash[name].each {|meth_name| 82: case mode 83: when 'strict' 84: return true if method_name.downcase == meth_name.downcase 85: when 'loose' 86: return true if method_name.downcase.include?(meth_name.downcase) 87: end 88: } 89: end 90: } 91: false 92: end
Return true if a Rails Action Controller class A module or object has no superclass hence the rescue clause
# File lib/rubyrun/rubyrun_utils__.rb, line 45 45: def is_rails_controller?(klass, mid) 46: return true if $rubyrun_controller_classes.include?(klass) 47: $rubyrun_rails_env ||= ENV['RAILS_ENV'] 48: begin 49: ($rubyrun_controller_classes << klass; return true) if $rubyrun_rails_env && 50: klass.to_s[-10, 10] == 'Controller' && 51: is_application_controller(klass) && 52: !klass.private_instance_methods(false).include?(return_method_name(mid)) 53: rescue 54: end 55: false 56: end