Class: Kumogata2::Utils
- Inherits:
-
Object
- Object
- Kumogata2::Utils
- Defined in:
- lib/kumogata2/utils.rb
Class Method Summary collapse
- .camelize(str) ⇒ Object
- .filter_backtrace(backtrace) ⇒ Object
- .get_user_host ⇒ Object
- .stringify(obj) ⇒ Object
Class Method Details
.camelize(str) ⇒ Object
3 4 5 6 7 |
# File 'lib/kumogata2/utils.rb', line 3 def camelize(str) str.to_s.split(/[-_]/).map {|i| i[0, 1].upcase + i[1..-1].downcase }.join end |
.filter_backtrace(backtrace) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kumogata2/utils.rb', line 9 def filter_backtrace(backtrace) filter_path = ['(eval)'] if defined?(Gem) filter_path.concat(Gem.path) filter_path << Gem.bindir end RbConfig::CONFIG.select {|k, v| k.to_s =~ /libdir/ }.each {|k, v| filter_path << v } filter_path = filter_path.map {|i| /\A#{Regexp.escape(i)}/ } backtrace.select do |path| path = path.split(':', 2).first not filter_path.any? {|i| i =~ path } end end |
.get_user_host ⇒ Object
29 30 31 32 33 34 |
# File 'lib/kumogata2/utils.rb', line 29 def get_user_host user = `whoami`.strip rescue '' host = `hostname`.strip rescue '' user_host = [user, host].select {|i| not i.empty? }.join('-') user_host.empty? ? nil : user_host end |
.stringify(obj) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kumogata2/utils.rb', line 36 def stringify(obj) case obj when Array obj.map {|v| stringify(v) } when Hash hash = {} obj.each do |k, v| hash[stringify(k)] = stringify(v) end hash else obj.to_s end end |