Module: RubyRunUtils__
- Includes:
- RubyRunGlobals
- Included in:
- RubyRunInitializer__, RubyRunInstrumentor__, RubyRunMonitor__, RubyRunTracer__
- Defined in:
- lib/rubyrun/rubyrun_utils__.rb
Overview
—————————————————————#
#
(C) Copyright Rubysophic Inc. 2007-2008 #
All rights reserved. #
#
Use, duplication or disclosure of the code is not permitted #
unless licensed. #
#
Last Updated: 7/09/08 #
—————————————————————#
#
RubyRunUtils__ is a module that owns common methods shared # by all the other RubyRun modules. #
#
—————————————————————#
Constant Summary
Constants included from RubyRunGlobals
RubyRunGlobals::RUBYRUN_ACTIVERECORD, RubyRunGlobals::RUBYRUN_CMD_EXIT, RubyRunGlobals::RUBYRUN_CMD_HARD_KILL, RubyRunGlobals::RUBYRUN_CMD_OBJECT_MAP, RubyRunGlobals::RUBYRUN_CMD_SOFT_KILL, RubyRunGlobals::RUBYRUN_CMD_STATUS, RubyRunGlobals::RUBYRUN_DIR_HASH_FILE, RubyRunGlobals::RUBYRUN_DOC_DIR, RubyRunGlobals::RUBYRUN_ETC_DIR, RubyRunGlobals::RUBYRUN_EXCLUDE_HASH_FILE, RubyRunGlobals::RUBYRUN_FIREWALL_HASH, RubyRunGlobals::RUBYRUN_HIGHLIGHT_THRESHOLD, RubyRunGlobals::RUBYRUN_INCLUDE_HASH_FILE, RubyRunGlobals::RUBYRUN_INNER_DISPATCH_HASH, RubyRunGlobals::RUBYRUN_KILL_3_STRING, RubyRunGlobals::RUBYRUN_LOG, RubyRunGlobals::RUBYRUN_MONITOR_TIMER, RubyRunGlobals::RUBYRUN_OPTS_FILE, RubyRunGlobals::RUBYRUN_OUTER_DISPATCH_HASH, RubyRunGlobals::RUBYRUN_OUTPUT_PERF_SUMMARY, RubyRunGlobals::RUBYRUN_OUTPUT_TXN_LOG, RubyRunGlobals::RUBYRUN_PREFIX, RubyRunGlobals::RUBYRUN_PREFIX_LENGTH, RubyRunGlobals::RUBYRUN_PROP_DEFAULTS, RubyRunGlobals::RUBYRUN_REPORT, RubyRunGlobals::RUBYRUN_SIGNATURE, RubyRunGlobals::RUBYRUN_STARTUP_ID_TYPE_PORT, RubyRunGlobals::RUBYRUN_STARTUP_ID_TYPE_PROCESS, RubyRunGlobals::RUBYRUN_THREAD_END_HASH, RubyRunGlobals::RUBYRUN_VIEW_HASH, RubyRunGlobals::RUBYRUN_WORKING_DIR_NAME
Instance Method Summary collapse
-
#env_var_exists?(var) ⇒ Boolean
Environment variable not defined or defined with nil value is deemed to be non-existent.
-
#fatal_exit(e) ⇒ Object
Error exit.
-
#get_caller_detail(n = 3) ⇒ Object
Retrieve caller details (filename, line number, method name).
-
#get_thread_id(th = Thread.current) ⇒ Object
Return a readable thread ID for the current thread of execution.
-
#is_action?(klass, mid) ⇒ Boolean
Return true if this is an action method in a controller class.
-
#is_application_controller(klass) ⇒ Object
Given a class, it’s deemed to be a Rails Action Controller if one of its ancestors is ApplicationController.
-
#is_in?(hash, klass, mid, mode = 'loose') ⇒ Boolean
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’.
-
#is_rails_controller?(klass) ⇒ Boolean
Return true if a Rails Action Controller class A module or object has no superclass hence the rescue clause.
-
#return_method_name(mid) ⇒ Object
Return method name since mid can be an method object ID or a string.
Instance Method Details
#env_var_exists?(var) ⇒ Boolean
Environment variable not defined or defined with nil value is deemed to be non-existent
33 34 35 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 33 def env_var_exists?(var) ENV[var].nil? || ENV[var] == '' ? false : true end |
#fatal_exit(e) ⇒ Object
Error exit
38 39 40 41 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 38 def fatal_exit(e) $stderr.print e.to_s + "\n" + e.backtrace.join("\n") exit(-1) end |
#get_caller_detail(n = 3) ⇒ Object
Retrieve caller details (filename, line number, method name)
27 28 29 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 27 def get_caller_detail(n=3) caller(0)[n].gsub("#{RUBYRUN_PREFIX}_", '').gsub('//', '/') end |
#get_thread_id(th = Thread.current) ⇒ Object
Return a readable thread ID for the current thread of execution
22 23 24 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 22 def get_thread_id(th=Thread.current) th.inspect.split(/Thread:0x/)[1].split(/ .*?>/)[0] end |
#is_action?(klass, mid) ⇒ Boolean
Return true if this is an action method in a controller class
62 63 64 65 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 62 def is_action?(klass, mid) !(klass.private_instance_methods(false).include?(return_method_name(mid)) || klass.protected_instance_methods(false).include?(return_method_name(mid))) end |
#is_application_controller(klass) ⇒ Object
Given a class, it’s deemed to be a Rails Action Controller if one of its ancestors is ApplicationController
69 70 71 72 73 74 75 76 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 69 def is_application_controller(klass) return false unless klass.superclass if klass.superclass == ApplicationController return true else is_application_controller(klass.superclass) end end |
#is_in?(hash, klass, mid, mode = 'loose') ⇒ Boolean
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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 84 def is_in?(hash, klass, mid, mode='loose') return false if hash.empty? [klass.to_s, klass.class.to_s, '*'].each {|name| if hash.has_key?(name) return true if hash[name].empty? method_name = return_method_name(mid) hash[name].each {|meth_name| case mode when 'strict' return true if method_name.downcase == meth_name.downcase when 'loose' return true if method_name.downcase.include?(meth_name.downcase) end } end } false end |
#is_rails_controller?(klass) ⇒ Boolean
Return true if a Rails Action Controller class A module or object has no superclass hence the rescue clause
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 45 def is_rails_controller?(klass) return true if $rubyrun_controller_classes.include?(klass) $rubyrun_rails_env ||= ENV['RAILS_ENV'] if $rubyrun_rails_env && !$rubyrun_monitor_thr.alive? && !$rubyrun_monitor $rubyrun_logger.info('----- RubyRun Thread Monitor Restarted -----') start_thread_monitor $rubyrun_monitor = true end begin ($rubyrun_controller_classes << klass; return true) if $rubyrun_rails_env && klass.to_s[-10, 10] == 'Controller' && is_application_controller(klass) rescue end false end |
#return_method_name(mid) ⇒ Object
Return method name since mid can be an method object ID or a string
104 105 106 |
# File 'lib/rubyrun/rubyrun_utils__.rb', line 104 def return_method_name(mid) mid.kind_of?(String) ? mid : mid.id2name end |